I'm trying to use the API in Mediawiki 1.17. I can't get logged in. I am getting a "WrongToken". I think I have the right lgtoken and session cookie, but I've never done any http programming, can anyone tell from the sequence below what I have wrong. Probably/hopefully it's some simple newbie mistake in not understanding how to handle a cookie or make a session not expire.
The user/password combo is able to login thru the normal interactive web interface.
Thanks
Levin -------------------------------------------------------------------------------- Begin Attempt -------------------------------------------------------------------------------- POST /mw/api.php HTTP/1.1 Cache-Control: no-cache Pragma: no-cache User-Agent: Java/1.7.0_09 Host: wiki.readytheory.com Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2 Connection: keep-alive Content-type: application/x-www-form-urlencoded Content-Length: 59
format=xml&action=login&lgname=mybot&lgpassword=pwd
-------------------------------------------------------------------------------- First response: --------------------------------------------------------------------------------
HTTP/1.1 200 OK Date: Thu, 24 Jan 2013 04:04:01 GMT Server: Apache/2.2.23 (Amazon) X-Powered-By: Mono Set-Cookie: wikidb_session=8foa9hj555b6re8mri4ajd7qi3; path=/; HttpOnly Cache-Control: private Content-Length: 162 Connection: close Content-Type: text/xml; charset=utf-8
<?xml version="1.0"?><api><login result="NeedToken" token="0e8287f8976207131b153ca2acf25cfb" cookieprefix="wikidb" sessionid="8foa9hj555b6re8mri4ajd7qi3" /></api>
-------------------------------------------------------------------------------- SECOND request with cookie --------------------------------------------------------------------------------
POST /mw/api.php HTTP/1.1 Cookie: wikidb_session=8foa9hj555b6re8mri4ajd7qi3 Cache-Control: no-cache Pragma: no-cache User-Agent: Java/1.7.0_09 Host: wiki.readytheory.com Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2 Connection: keep-alive Content-type: application/x-www-form-urlencoded Content-Length: 99
format=xml&action=login&lgname=mybot&lgpassword=pwd&lgtoken=0e8287f8976207131b153ca2acf25cfb
-------------------------------------------------------------------------------- second response, where I get "WrongToken" --------------------------------------------------------------------------------
HTTP/1.1 200 OK Date: Thu, 24 Jan 2013 04:04:01 GMT Server: Apache/2.2.23 (Amazon) X-Powered-By: Mono Cache-Control: private Content-Length: 61 Connection: close Content-Type: text/xml; charset=utf-8
<?xml version="1.0"?><api><login result="WrongToken" /></api>
Could you tell which programming language you used ?
In case you are using python, have a look at https://github.com/yuvipanda/python-mwapi, for go-lang https://github.com/kracekumar/go-mwapi.
On Fri, Jan 25, 2013 at 9:24 AM, Levin Magruder levin_magruder@yahoo.comwrote:
I'm trying to use the API in Mediawiki 1.17. I can't get logged in. I am getting a "WrongToken". I think I have the right lgtoken and session cookie, but I've never done any http programming, can anyone tell from the sequence below what I have wrong. Probably/hopefully it's some simple newbie mistake in not understanding how to handle a cookie or make a session not expire.
The user/password combo is able to login thru the normal interactive web interface.
Thanks
Levin
Begin Attempt
POST /mw/api.php HTTP/1.1 Cache-Control: no-cache Pragma: no-cache User-Agent: Java/1.7.0_09 Host: wiki.readytheory.com Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2 Connection: keep-alive Content-type: application/x-www-form-urlencoded Content-Length: 59
format=xml&action=login&lgname=mybot&lgpassword=pwd
First response:
HTTP/1.1 200 OK Date: Thu, 24 Jan 2013 04:04:01 GMT Server: Apache/2.2.23 (Amazon) X-Powered-By: Mono Set-Cookie: wikidb_session=8foa9hj555b6re8mri4ajd7qi3; path=/; HttpOnly Cache-Control: private Content-Length: 162 Connection: close Content-Type: text/xml; charset=utf-8
<?xml version="1.0"?><api><login result="NeedToken"
token="0e8287f8976207131b153ca2acf25cfb" cookieprefix="wikidb" sessionid="8foa9hj555b6re8mri4ajd7qi3" /></api>
SECOND request with cookie
POST /mw/api.php HTTP/1.1 Cookie: wikidb_session=8foa9hj555b6re8mri4ajd7qi3 Cache-Control: no-cache Pragma: no-cache User-Agent: Java/1.7.0_09 Host: wiki.readytheory.com Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2 Connection: keep-alive Content-type: application/x-www-form-urlencoded Content-Length: 99
format=xml&action=login&lgname=mybot&lgpassword=pwd&lgtoken=0e8287f8976207131b153ca2acf25cfb
second response, where I get "WrongToken"
HTTP/1.1 200 OK Date: Thu, 24 Jan 2013 04:04:01 GMT Server: Apache/2.2.23 (Amazon) X-Powered-By: Mono Cache-Control: private Content-Length: 61 Connection: close Content-Type: text/xml; charset=utf-8
<?xml version="1.0"?><api><login result="WrongToken" /></api>
Mediawiki-api mailing list Mediawiki-api@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-api
On Thu, Jan 24, 2013 at 10:54 PM, Levin Magruder levin_magruder@yahoo.com wrote:
I'm trying to use the API in Mediawiki 1.17.
You should probably upgrade.
Content-Length: 59
format=xml&action=login&lgname=mybot&lgpassword=pwd
The length of the post data you have here is 51 bytes. Your bot's real username and password together must be 8 bytes longer than "mybot" and "pwd".
Content-Length: 99
format=xml&action=login&lgname=mybot&lgpassword=pwd&lgtoken=0e8287f8976207131b153ca2acf25cfb
The length of the post data you have here is 92 bytes. You added 41 bytes, which is consistent with the length of the "&lgtoken=0e8287f8976207131b153ca2acf25cfb" string that was added to the post data. But you only added 40 to the Content-Length header, so the server is probably seeing "&lgtoken=0e8287f8976207131b153ca2acf25cf", with the last character is cut off.
Also, BTW:
User-Agent: Java/1.7.0_09
It's good practice to use a custom user agent for your bot, including an email address or URL to a webpage with a way to contact you, instead of something generic like this. On wiki.readytheory.com it may not matter, but if you ever decide to use your bot on a WMF wiki a custom User-Agent is required.
Thanks Brad. Content length is probably the problem. If I were sending content say like:
format=xml&action=login&lgname=mybot&lgpassword=pwd[some trailing spaces]
and the Content-Length: included some of those trailing spaces, would the spaces be considered part of the passwd?
Kracekumar Ramaraju else asked about the programming language - it's code generated from Talend Open Studio. I didn't bother specifying a User-Agent since I'd only use it against my personal wiki.
Levin
--- On Fri, 1/25/13, Brad Jorsch bjorsch@wikimedia.org wrote:
From: Brad Jorsch bjorsch@wikimedia.org Subject: Re: [Mediawiki-api] Can't login to MW 1.71 - "WrongToken" To: "MediaWiki API announcements & discussion" mediawiki-api@lists.wikimedia.org Date: Friday, January 25, 2013, 8:36 AM On Thu, Jan 24, 2013 at 10:54 PM, Levin Magruder levin_magruder@yahoo.com wrote:
I'm trying to use the API in Mediawiki 1.17.
You should probably upgrade.
Content-Length: 59
format=xml&action=login&lgname=mybot&lgpassword=pwd
The length of the post data you have here is 51 bytes. Your bot's real username and password together must be 8 bytes longer than "mybot" and "pwd".
Content-Length: 99
format=xml&action=login&lgname=mybot&lgpassword=pwd&lgtoken=0e8287f8976207131b153ca2acf25cfb
The length of the post data you have here is 92 bytes. You added 41 bytes, which is consistent with the length of the "&lgtoken=0e8287f8976207131b153ca2acf25cfb" string that was added to the post data. But you only added 40 to the Content-Length header, so the server is probably seeing "&lgtoken=0e8287f8976207131b153ca2acf25cf", with the last character is cut off.
Also, BTW:
User-Agent: Java/1.7.0_09
It's good practice to use a custom user agent for your bot, including an email address or URL to a webpage with a way to contact you, instead of something generic like this. On wiki.readytheory.com it may not matter, but if you ever decide to use your bot on a WMF wiki a custom User-Agent is required.
Mediawiki-api mailing list Mediawiki-api@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-api
On Fri, Jan 25, 2013 at 10:15 AM, Levin Magruder levin_magruder@yahoo.com wrote:
Thanks Brad. Content length is probably the problem. If I were sending content say like:
format=xml&action=login&lgname=mybot&lgpassword=pwd[some trailing spaces]
and the Content-Length: included some of those trailing spaces, would the spaces be considered part of the passwd?
Yes. You shouldn't send any trailing spaces, send exactly Content-Length bytes.
mediawiki-api@lists.wikimedia.org