Skip to content

Commit

Permalink
fix: add a timeout to GBIF API requests
Browse files Browse the repository at this point in the history
  • Loading branch information
jrdh authored Mar 19, 2024
1 parent e5b9ccd commit adfb935
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions ckanext/nhm/lib/external_links.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,18 @@ def _get_gbif_record(occurrence_id: str, institution_code: str) -> Optional[dict
if occurrence_id is None or institution_code is None:
return None

r = requests.get(
"https://api.gbif.org/v1/occurrence/search",
params={
"occurrenceID": occurrence_id,
"institutionCode": institution_code,
},
)
try:
r = requests.get(
"https://api.gbif.org/v1/occurrence/search",
params={
"occurrenceID": occurrence_id,
"institutionCode": institution_code,
},
timeout=5
)
except requests.Timeout:
return None

if r.ok:
results = r.json()
if results.get("count") == 1:
Expand Down

0 comments on commit adfb935

Please sign in to comment.