From 845666dd5af88064deb5fb880c15660df3423ca1 Mon Sep 17 00:00:00 2001 From: Edward Betts Date: Tue, 30 Jun 2020 14:28:34 +0100 Subject: [PATCH] Switch to POST for Commons API call Avoid crash caused by URL being too long. --- depicts/commons.py | 2 +- depicts/mediawiki.py | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/depicts/commons.py b/depicts/commons.py index ccac806..bd695a9 100644 --- a/depicts/commons.py +++ b/depicts/commons.py @@ -25,7 +25,7 @@ def image_detail(filenames, thumbheight=None, thumbwidth=None): call_params = params.copy() call_params['titles'] = '|'.join(f'File:{f}' for f in cur) - r = mediawiki.api_call(call_params, api_url=commons_url) + r = mediawiki.api_post(call_params, api_url=commons_url) for image in r.json()['query']['pages']: filename = utils.drop_start(image['title'], 'File:') diff --git a/depicts/mediawiki.py b/depicts/mediawiki.py index 7fcb75f..39b414d 100644 --- a/depicts/mediawiki.py +++ b/depicts/mediawiki.py @@ -24,6 +24,16 @@ def api_call(params, api_url=wikidata_url): r = requests.get(api_url, params=call_params, timeout=5) return r +def api_post(params, api_url=wikidata_url): + call_params = { + 'format': 'json', + 'formatversion': 2, + **params, + } + + r = requests.post(api_url, data=call_params, timeout=5) + return r + def get_list(list_name, **params): r = api_call({'action': 'query', 'list': list_name, **params}) return r.json()['query'][list_name]