Skip to content

Commit

Permalink
Catch 404 error (#1449)
Browse files Browse the repository at this point in the history
* Catch 404 error

* catch 404

* remove print space

* master merged & update print msg

Co-authored-by: henrykironde <henrykironde@gmail.com>
  • Loading branch information
coolalexzb and henrykironde committed Mar 23, 2020
1 parent 3c9b68f commit 2eb4ab5
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions retriever/lib/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from collections import OrderedDict
from math import ceil
from urllib.request import urlretrieve
from urllib.error import HTTPError

import requests
from requests.exceptions import InvalidSchema
Expand Down Expand Up @@ -475,8 +476,9 @@ def download_file(self, url, filename):
miniters=1,
desc='Downloading {}'.format(filename),
)

try:
requests.get(
response = requests.get(
url,
allow_redirects=True,
stream=True,
Expand All @@ -488,11 +490,21 @@ def download_file(self, url, filename):
hooks={'response': reporthook(progbar, path)},
)

if response.status_code == 404:
print("Error 404: The data source or server not found")
os.remove(path)
return None

except InvalidSchema:
urlretrieve(url, path, reporthook=reporthook(progbar))
try:
urlretrieve(url, path, reporthook=reporthook(progbar))
except HTTPError as e:
print(f"HTTPError: {e.code}")
return None

self.use_cache = True
progbar.close()
return True

def download_files_from_archive(
self,
Expand Down

0 comments on commit 2eb4ab5

Please sign in to comment.