Skip to content

Commit

Permalink
Add timeout for long response times
Browse files Browse the repository at this point in the history
  • Loading branch information
J535D165 committed Aug 23, 2023
1 parent bac4570 commit 6572668
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions datahugger/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,12 +178,12 @@ def _base_request(

# if netloc is doi.org, follow the redirect
if uri.hostname in URL_RESOLVE:
r = requests.head(url, allow_redirects=True)
r = requests.head(url, allow_redirects=True, timeout=(3, 10))
if r.status_code == 404 and r.url and r.url.startswith("https://doi.org"):
raise DOIError(f"DOI {doi} not found in the DOI system")
elif r.status_code == 405:
# head request not allowed, try get request
r = requests.get(url, allow_redirects=True)
r = requests.get(url, allow_redirects=True, timeout=(3, 10))
else:
r.raise_for_status()

Expand Down

0 comments on commit 6572668

Please sign in to comment.