From ae7d68462f57a85e79d4146e030f17d750a55dc8 Mon Sep 17 00:00:00 2001 From: Edward Betts Date: Sun, 20 Jun 2021 14:47:04 +0200 Subject: [PATCH] Show Wikidata API reply on JSON parse fail --- matcher/wikidata_api.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/matcher/wikidata_api.py b/matcher/wikidata_api.py index ab0ad5a..062e907 100644 --- a/matcher/wikidata_api.py +++ b/matcher/wikidata_api.py @@ -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]