Switch to POST for Commons API call
Avoid crash caused by URL being too long.
This commit is contained in:
parent
8c715fe148
commit
845666dd5a
|
@ -25,7 +25,7 @@ def image_detail(filenames, thumbheight=None, thumbwidth=None):
|
||||||
call_params = params.copy()
|
call_params = params.copy()
|
||||||
call_params['titles'] = '|'.join(f'File:{f}' for f in cur)
|
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']:
|
for image in r.json()['query']['pages']:
|
||||||
filename = utils.drop_start(image['title'], 'File:')
|
filename = utils.drop_start(image['title'], 'File:')
|
||||||
|
|
|
@ -24,6 +24,16 @@ def api_call(params, api_url=wikidata_url):
|
||||||
r = requests.get(api_url, params=call_params, timeout=5)
|
r = requests.get(api_url, params=call_params, timeout=5)
|
||||||
return r
|
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):
|
def get_list(list_name, **params):
|
||||||
r = api_call({'action': 'query', 'list': list_name, **params})
|
r = api_call({'action': 'query', 'list': list_name, **params})
|
||||||
return r.json()['query'][list_name]
|
return r.json()['query'][list_name]
|
||||||
|
|
Loading…
Reference in a new issue