From 0a6f5982950b37f2f8308a451463d93cf0187682 Mon Sep 17 00:00:00 2001 From: Valentin Lorentz Date: Mon, 8 Nov 2021 23:41:26 +0100 Subject: [PATCH] Geography: Set a better user-agent to access Wikidata --- plugins/Geography/wikidata.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/plugins/Geography/wikidata.py b/plugins/Geography/wikidata.py index cd5f28497..959d2c970 100644 --- a/plugins/Geography/wikidata.py +++ b/plugins/Geography/wikidata.py @@ -110,7 +110,12 @@ LIMIT 1 def _query_sparql(query): params = {"format": "json", "query": query} url = SPARQL_URL + "?" + urllib.parse.urlencode(params) - content = utils.web.getUrlContent(url) + + # Comply with https://meta.wikimedia.org/wiki/User-Agent_policy + headers = utils.web.defaultHeaders.copy() + headers["User-agent"] += " https://github.com/progval/Limnoria/ - Geography plugin" + + content = utils.web.getUrlContent(url, headers=headers) return json.loads(content) def timezone_from_qid(location_qid):