Skip to content

Commit

Permalink
Fix a bug that downloading https:// urls (behind a proxy) was not pos…
Browse files Browse the repository at this point in the history
…sible

Replaced the urllib method of downloading files by code that uses urllib2. It seems that urllib is not able to download files from https urls.
See here qiime#57
  • Loading branch information
phuseman committed Feb 6, 2014
1 parent ad73cc3 commit c9cb2d3
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions lib/util.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from urllib import FancyURLopener
import urllib2

import commands
import logging
Expand Down Expand Up @@ -445,14 +445,8 @@ def unzip_file(filePath, newLocation):
def progress_reporter(s):
log.debug(s)

class URLOpener(FancyURLopener):
def http_error_default(self, url, fp, errcode, errmsg, headers):
msg = 'ERROR: Could not download %s\nIs the URL valid?' % url
raise IOError, msg

def download_file(URL, dest_dir, local_file, num_retries = 4):
log.info('Downloading %s' % URL)
url_opener = URLOpener()
localFP = os.path.join(dest_dir, local_file)
tmpDownloadFP = '%s.part' % localFP
progress_reporter('Starting %s download' % local_file)
Expand All @@ -462,11 +456,12 @@ def download_file(URL, dest_dir, local_file, num_retries = 4):
rc = 1
while download_failed > 0:
try:
tmpLocalFP, headers = url_opener.retrieve(URL, \
tmpDownloadFP)
download=urllib2.urlopen(URL)
with open(tmpDownloadFP,'wb') as output:
output.write(download.read())
os.rename(tmpDownloadFP, localFP)
rc = 0
except IOError, msg:
except urllib2.URLError:
if download_failed == 1:
progress_reporter('Download of %s failed.' % URL)
else:
Expand Down

0 comments on commit c9cb2d3

Please sign in to comment.