Switch to POST for Commons API call

Avoid crash caused by URL being too long.
This commit is contained in:
Edward Betts 2020-06-30 14:28:34 +01:00
parent 8c715fe148
commit 845666dd5a
2 changed files with 11 additions and 1 deletions

View file

@ -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:')

View file

@ -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]