Skip to content

Commit

Permalink
error messages for failed downloads
Browse files Browse the repository at this point in the history
  • Loading branch information
jowagner committed Dec 22, 2015
1 parent 7b97bf1 commit 33b0965
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions scripts/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,21 @@
def download(url, dirpath):
filename = url.split('/')[-1]
filepath = os.path.join(dirpath, filename)
u = urllib2.urlopen(url)
f = open(filepath, 'wb')
filesize = int(u.info().getheaders("Content-Length")[0])
try:
u = urllib2.urlopen(url)
except:
print("URL %s failed to open" %url)
raise Exception
try:
f = open(filepath, 'wb')
except:
print("Cannot write %s" %filepath)
raise Exception
try:
filesize = int(u.info().getheaders("Content-Length")[0])
except:
print("URL %s failed to report length" %url)
raise Exception
print("Downloading: %s Bytes: %s" % (filename, filesize))

downloaded = 0
Expand Down

0 comments on commit 33b0965

Please sign in to comment.