From ef3c0c84e3bea97cc88675a435f470fbcee4e892 Mon Sep 17 00:00:00 2001 From: Alexis Asseman <33075224+aasseman@users.noreply.github.com> Date: Thu, 25 Apr 2019 18:19:07 -0700 Subject: [PATCH 1/2] Replaced urllibs by requests --- ptp/components/utils/io.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/ptp/components/utils/io.py b/ptp/components/utils/io.py index 8ec234e..5f435fb 100644 --- a/ptp/components/utils/io.py +++ b/ptp/components/utils/io.py @@ -20,7 +20,7 @@ import shutil import zipfile import time -import urllib +import requests from pathlib import Path @@ -181,7 +181,20 @@ def download(folder, filename, url): # Download. file_result = os.path.join(os.path.expanduser(folder), filename) - urllib.request.urlretrieve(url, os.path.expanduser(file_result), reporthook) + + with open(os.path.expanduser(file_result), "wb") as f: + global start_time + start_time = time.time() + r = requests.get(url) + content_length = int(r.headers.get('content-length', None)) + count = 0 + + for chunk in r.iter_content(chunk_size=1024): + if chunk: + f.write(chunk) + count += 1 + reporthook(count, 1024, content_length) + #self.logger.info('Downloading {}'.format(url)) def reporthook(count, block_size, total_size): From f318d3666a9f4e0b4e0abfbf3716571653ad220c Mon Sep 17 00:00:00 2001 From: Alexis Asseman <33075224+aasseman@users.noreply.github.com> Date: Thu, 25 Apr 2019 18:22:53 -0700 Subject: [PATCH 2/2] Added requests dependency to setup.py --- setup.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 2326d54..17c668e 100644 --- a/setup.py +++ b/setup.py @@ -173,7 +173,8 @@ #'torchtext', 'torchvision', 'torch', - 'PyYAML' + 'PyYAML', + 'requests' ], # List additional groups of dependencies here (e.g. development