Template:REST API GET sample code (python)

From Linux Web Expert

import requests

url = 'https://en.wikipedia.org/w/rest.php/some/path'
headers = {
    'User-Agent': 'MediaWiki REST API docs examples/0.1 (https://www.mediawiki.org/wiki/API_talk:REST_API)'
}


response = requests.get(url, headers=headers)
data = response.json()

print(data)
# Sample code
import requests

url = 'https://test.example/foo'
headers = {
    'User-Agent': 'MediaWiki REST API docs examples/0.1 (https://www.mediawiki.org/wiki/API_talk:REST_API)'
}
params = {
    'x': '1',
    'y': '2'
}

response = requests.get(url, headers=headers, params=params)
data = response.json()

print(data)
Template documentation