Hello list,
I've read many posts around this error but I cannot figure out why I did not get it. I hope you can shine a light to it, please.
My system: MW 1.21.1 I use AUTH_REMOTEUSER modul and its working fine. It seems that it works with the api.php too. (fetching info with my user rights)
Well, referring to http://en.wikipedia.org/w/api.php I want to do the action=edit to create or edit pages.
So I start to fetch my login token. wget --http-user=myuser --http-password=mypwd " https://localhost/wiki/api.php?action=query&prop=info%7Crevisions&in...
then I get the xml back
... <page ns="0" title="mynewpage" missing="" starttimestamp="2013-09-26T21:38:59Z" edittoken="396fb7fbd9a308620d460e92e611d100+\" /></pages> ...
So I extract this edittoken-element and simply create a new page. ($newtoken=edittoken)
wget --http-user=myuser --http-password=mypwd --header="Content-Type: application/x-www-form-urlencoded" "https://localhost/wiki/api.php" --post-data "action=edit&title=mynewpage&text=test&token=$newtoken"
I get back: error code="badtoken" info="Invalid token"
After investigation I found a webpage https://www.mediawiki.org/wiki/API:Edit
which describes the token characters (The token that you received is terminated with +, this needs to be urlencoded (so it will end with %2B%5C) before it is passed back)
I tried it with this hint and without it.... but with no success.... I also tried to do a normal login (action=login) but it does not help.
For information... my user does not have any password because of active directory authentication by the webserver. So I can not add the parameter lgname=myuser&lgpassword ....
Please can you help me?
Thank you very much! Andreas
On Thu, Sep 26, 2013 at 5:58 PM, Andreas Mrvka andreas.mrvka@gmail.com wrote:
wget --http-user=myuser --http-password=mypwd "https://localhost/wiki/api.php?action=query&prop=info%7Crevisions&in...
[...]
wget --http-user=myuser --http-password=mypwd --header="Content-Type: application/x-www-form-urlencoded" "https://localhost/wiki/api.php" --post-data "action=edit&title=mynewpage&text=test&token=$newtoken"
Besides percent-encoding the edit token, you also need to pass back the cookies from the first request into the second.
You'll want to give the --keep-session-cookies and --save-cookies options to the first wget command, and additionally --load-cookies to the second.
Hello Brad,
thank you for your fast response! I extended my script with your additions and it works now! :-)
I also tried the save/load cookies before but.... --keep-session-cookies was the showstopper!
With this setting it works!
Thanks Andreas
2013/9/27 Brad Jorsch (Anomie) bjorsch@wikimedia.org
On Thu, Sep 26, 2013 at 5:58 PM, Andreas Mrvka andreas.mrvka@gmail.com wrote:
wget --http-user=myuser --http-password=mypwd "
https://localhost/wiki/api.php?action=query&prop=info%7Crevisions&in...
[...]
wget --http-user=myuser --http-password=mypwd --header="Content-Type: application/x-www-form-urlencoded" "https://localhost/wiki/api.php" --post-data "action=edit&title=mynewpage&text=test&token=$newtoken"
Besides percent-encoding the edit token, you also need to pass back the cookies from the first request into the second.
You'll want to give the --keep-session-cookies and --save-cookies options to the first wget command, and additionally --load-cookies to the second.
-- Brad Jorsch (Anomie) Software Engineer Wikimedia Foundation
Mediawiki-api mailing list Mediawiki-api@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-api
mediawiki-api@lists.wikimedia.org