Skip to content

Commit

Permalink
Raise error during downloading (#1013)
Browse files Browse the repository at this point in the history
* Raise error during downloading

* Fix py2 error and lint
  • Loading branch information
fmassa authored Jun 13, 2019
1 parent f9348a0 commit 7693c89
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
7 changes: 7 additions & 0 deletions test/test_datasets_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@ def test_download_url_retry_http(self):
warnings.warn(msg, RuntimeWarning)
raise unittest.SkipTest(msg)

@unittest.skipIf(sys.version_info < (3,), "Python2 doesn't raise error")
def test_download_url_dont_exist(self):
with get_tmp_dir() as temp_dir:
url = "http://github.com/pytorch/vision/archive/this_doesnt_exist.zip"
with self.assertRaises(URLError):
utils.download_url(url, temp_dir)

def test_extract_zip(self):
with get_tmp_dir() as temp_dir:
with tempfile.NamedTemporaryFile(suffix='.zip') as f:
Expand Down
4 changes: 3 additions & 1 deletion torchvision/datasets/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def download_url(url, root, filename=None, md5=None):
url, fpath,
reporthook=gen_bar_updater()
)
except OSError:
except urllib.error.URLError as e:
if url[:5] == 'https':
url = url.replace('https:', 'http:')
print('Failed download. Trying https -> http instead.'
Expand All @@ -91,6 +91,8 @@ def download_url(url, root, filename=None, md5=None):
url, fpath,
reporthook=gen_bar_updater()
)
else:
raise e


def list_dir(root, prefix=False):
Expand Down

0 comments on commit 7693c89

Please sign in to comment.