1

我无法访问我的媒体 wiki 站点的编辑令牌。使用以下代码,我应该能够使用 simpleMediWiki 站点登录,然后请求编辑令牌,最后进行编辑。不幸的是,我收到一个错误,即“编辑”参数是一个无法识别的参数:

{'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']})
4

1 回答 1

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'] 
于 2012-11-14T08:00:16.643 回答