我无法访问媒体wiki网站的编辑令牌。使用以下代码,我应该能够使用simpleMediWiki站点登录,然后请求编辑令牌,然后最终进行编辑。不幸的是,我收到一个错误,即'edit'参数是一个无法识别的参数:
{'error': {'info': "Unrecognized value for parameter 'action': token", 'code': 'unknown_action'}}
这是我的代码:
from simplemediawiki import MediaWiki
wiki = MediaWiki('http://domain/api.php')
#the following logs me in
loginData = wiki.call({'action':'login', 'lgname':'myUserName','lgpassword':'myPassword'})
#The following is a resubmission of the login token
personalLoginData = wiki.call({'action':'login', 'lgname':'myUserName','lgpassword':'myPassword','lgtoken': loginData['login']['token']})
#the following is THE TROUBLESOME REQUEST FOR AN EDIT TOKEN
editTokenDict = wiki.call({'action':'tokens','type':'edit'})
#the following is an edit
results = wiki.call({'action':'edit','title':"ArticleTitle",'text':"This is the page",'tokens':editTokenDict['login']['token']})
答案 0 :(得分:0)
我想通了,答案是mediaWiki 1.19.2不支持这个查询选项。最新版本的mediaWiki支持此查询选项,但是对于其他所有内容 - 您必须使用查询操作来访问编辑令牌。例如:
returnData = wiki.call({'action':'query','prop':'info', 'titles':'Main_Page','intoken':'edit'});
#keep in mind the edittoken is the same for every page, and that's why we preform the query action on the Main_Page
#then you must use the following to get the edittoken:
edittoken = returnData['query']['pages']['1']['edittoken']