2012-11-13 17 views
1

我無法訪問我的媒體維基網站的編輯標記。使用以下代碼,我應該能夠使用simpleMediWiki網站進行登錄,然後請求編輯標記,然後進行編輯。不幸的是我發現了一個錯誤的「編輯」參數是無法識別的參數:使用simpleMediaWiki訪問編輯標記(操作字段未被識別)

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

一個錯字? 'action'的值應該是'token',而不是'token'。 – Tgr

+0

我想通了,答案是mediaWiki 1.19.2不支持這個查詢選項。最新版本的mediaWiki支持這個查詢選項,但對於其他任何情況 - 您必須使用查詢操作來訪問編輯標記。例如:returnData = wiki.call({'action':'query','prop':'info','titles':'Main_Page','intoken':'edit'});#記住edittoken每個頁面都是一樣的,這就是爲什麼我們在Main_Page上執行查詢操作#那麼你必須使用以下命令來獲得edittoken:edittoken = returnData ['query'] ['pages'] ['1'] ['' edittoken'] – LucianNovo

回答

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