diff --git a/download_lt.py b/download_lt.py index 7a65a9b..4def5c7 100755 --- a/download_lt.py +++ b/download_lt.py @@ -9,6 +9,7 @@ import subprocess import sys import os +import requests from contextlib import closing from distutils.spawn import find_executable @@ -128,7 +129,7 @@ def download_lt(update=False): return with closing(TemporaryFile()) as t: - with closing(urlopen(url)) as u: + with closing(requests.get(url,stream=True)) as u: content_len = int(u.headers['Content-Length']) sys.stdout.write( @@ -139,10 +140,7 @@ def download_lt(update=False): chunk_len = content_len // 100 data_len = 0 - while True: - data = u.read(chunk_len) - if not data: - break + for data in u.iter_content(chunk_len): data_len += len(data) t.write(data) sys.stdout.write(