Topic on Project:Support desk

Add a page to the local mediawiki using API

4
Summary by Taavi

Wrong endpoint, probably. Anyways a 8-month-old topic.

SumanGadhawal (talkcontribs)

Hi all,

I am new here and currently I am trying to generate login token for my local url http://localhost/mediawiki/index.php/Main_Page but i am getting response 404


here is my code


import requests
S = requests.Session()
URL = "http://localhost/mediawiki/index.php/Main_Page"
# Retrieve login token first
PARAMS_0 = {
    'action':"query",
    'meta':"tokens",
    'type':"login",
    'format':"json"
}
R = S.get(url=URL, params=PARAMS_0)
print(R)
DATA = R.json()
LOGIN_TOKEN = DATA['query']['tokens']['logintoken']
print('data',DATA)
Clump (talkcontribs)

404 is not found---does the url work in a browser? Either way, the API entry point is not index.php/Main_Page, it is api.php. See API:Main_page#Endpoint.

SumanGadhawal (talkcontribs)
Ciencia Al Poder (talkcontribs)

Do you realize you're typing index.php instead of api.php?