Show Wikidata API reply on JSON parse fail

This commit is contained in:
Edward Betts 2021-06-20 14:47:04 +02:00
parent a4f7c09138
commit ae7d68462f

View file

@ -1,5 +1,6 @@
import requests
import json
import simplejson.errors
wd_api_url = "https://www.wikidata.org/w/api.php"
@ -54,7 +55,12 @@ def get_recent_changes(**kwargs):
def get_entity(qid):
data = api_get({"action": "wbgetentities", "ids": qid}).json()
r = api_get({"action": "wbgetentities", "ids": qid})
try:
data = r.json()
except simplejson.errors.JSONDecodeError:
print(r.text)
raise
if "entities" not in data:
print(json.dumps(data, indent=2))
return data["entities"][qid]