Topic on User talk:Martyav/Sandbox/API:Images

Jump to navigation Jump to search
SSethi (WMF) (talkcontribs)
Martyav (talkcontribs)

Here is the script I've been working on this morning. However, it prints: {'batchcomplete': '', 'query': {'pages': {'-1': {'ns': 0, 'title': 'Albert Einstein', 'missing': ''}}}}

which does not seem to be correct?

#!/usr/bin/python3

"""

images.py

MediaWiki Action API Code Samples

Demo of `Images` module: Sending GET request to images

MIT license

"""

# Note: This code relies on the third party library, requests.

# Be sure to install it via your favorite package manager!

import requests

S = requests.Session()

URL = "https://mediawiki.org//w/api.php"

# Send a GET request to the images endpoint.

PARAMS = {

'action':'query',

'format':'json',

'prop':'images',

'titles':'Albert Einstein'

}

R = S.get(url=URL, params=PARAMS)

DATA = R.json()

print(DATA)

SSethi (WMF) (talkcontribs)

@Martyav Hello Marty! this is happening because you are trying to look for files on the page with title "Albert Einstein" on MediaWiki.org, though there is not a page like with this title that exists there. It is on English Wikipedia instead. So, you would have to change the endpoint url in your code.

Martyav (talkcontribs)

Ha! Thanks! I should have realized.

SSethi (WMF) (talkcontribs)

@Martyav Glad you got it to work :-) I've left some comments on your pull request. Also, improvements are welcome to the API:Images page in your Sandbox following suggestions in the comment I've added above.

SSethi (WMF) (talkcontribs)
Martyav (talkcontribs)

Thanks for merging in my changes! I felt really happy this morning.

I made the corrections and also moved around the section ordering on this page to match Didicodes.

SSethi (WMF) (talkcontribs)

Awesome! :) That makes me happy too!! User:Martyav/Sandbox/API:Images is ready to be migrated from your Sandbox to main namespace on MediaWiki.org: API:Images. When you publish your changes, you want to add a comment something like: "Rewrite; using the API documentation template (https://www.mediawiki.org/wiki/API:Documentation_template) to format this page" (see my last edit here: https://www.mediawiki.org/w/index.php?title=API:Prefixsearch&action=history). Also, then you can update the Phabricator task and your name in the "Done" column

Reply to "Feedback 1.0"