Skip to content
This repository has been archived by the owner on Sep 23, 2023. It is now read-only.

Fix a bug that downloading https:// urls (behind a proxy) was not possib... #59

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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