Download without status updates if server does not report file size. Closes #771.

This commit is contained in:
Jussi Pakkanen 2016-09-09 22:10:31 +03:00
parent 49583ccfab
commit 3d8876bf59
1 changed files with 7 additions and 1 deletions

View File

@ -139,7 +139,13 @@ class Resolver:
else: else:
resp = urllib.request.urlopen(url) resp = urllib.request.urlopen(url)
with contextlib.closing(resp) as resp: with contextlib.closing(resp) as resp:
dlsize = int(resp.info()['Content-Length']) try:
dlsize = int(resp.info()['Content-Length'])
except TypeError:
dlsize = None
if dlsize is None:
print('Downloading file of unknown size.')
return resp.read()
print('Download size:', dlsize) print('Download size:', dlsize)
print('Downloading: ', end='') print('Downloading: ', end='')
sys.stdout.flush() sys.stdout.flush()