Skip to content

Commit

Permalink
Merge pull request #560 from NFDI4BIOIMAGE/git-bob-mod-OoDahpiXBY
Browse files Browse the repository at this point in the history
Add try-except blocks to handle JSON decoding errors in Zenodo scripts.
  • Loading branch information
haesleinhuepf authored Dec 31, 2024
2 parents b6ec185 + 69630ac commit d18ec67
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
12 changes: 7 additions & 5 deletions scripts/auto-add-from-zenodo-communities.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,13 @@ def main():
response = requests.get('https://zenodo.org/api/records',
params={'communities': community,
'access_token': token})
online_data = response.json()
hits = online_data["hits"]["hits"]
urls = [u["links"]["self_html"] for u in hits]

try:
online_data = response.json()
hits = online_data["hits"]["hits"]
urls = [u["links"]["self_html"] for u in hits]
except requests.exceptions.JSONDecodeError:
print(f"Error decoding JSON for community: {community}")
continue

# compare which new is not in old

Expand Down Expand Up @@ -100,6 +103,5 @@ def main():




if __name__ == "__main__":
main()
6 changes: 5 additions & 1 deletion scripts/generate_link_lists.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,11 @@ def read_zenodo(record):

# Download the file
response = requests.get(url)
data = response.json()
try:
data = response.json()
except json.JSONDecodeError:
data = {}

return data


Expand Down

0 comments on commit d18ec67

Please sign in to comment.