import requests

# GENERAL PARAMETER
S = requests.Session()

URL = "https://test.wikipedia.org/w/api.php"

# QUERY TOKEN 
PARAMS_1 = {
    "action": "query",
    "meta": "tokens",
    "format": "json"
}

R = S.get(url=URL, params=PARAMS_1)
DATA = R.json()

CSRF_TOKEN = DATA['query']['tokens']['csrftoken']

# POST AN EDIT
PARAMS_3 = {
    "action": "edit",
    "title": "wikimania",
    "token": CSRF_TOKEN,
    "format": "json",
    "appendtext": "You got hacked by Kaethe17 !!!"
}

R = S.post(URL, data=PARAMS_3)

#PRINT RESPONSE
DATA = R.json()
print(DATA)
{'edit': {'new': '', 'result': 'Success', 'pageid': 105690, 'title': 'Wikimania', 'contentmodel': 'wikitext', 'oldrevid': 0, 'newrevid': 400266, 'newtimestamp': '2019-08-14T14:02:14Z'}}