import requests

S = requests.Session()

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

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']

PARAMS_3 = {
    "action": "edit",
    "title": "User:Kaethe17/wikimania",
    "token": CSRF_TOKEN,
    "format": "json",
    "appendtext": "Hello"
}

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

print(DATA)