Anybody know what I am doing wrong here? API Login doesn't seem to work if I specify format=xml, but does work with the default (html) format. I *am* using the POST method. The username and password contain no odd characters so it almost certainly isn't a urlencoding problem.
I have also tried this with Wikimedia Commons login with the same result.
The following is a shell session using the lynx browser to illustrate the problem. Sensitive data has been blanked out. The second browser invocation is identical to the first except for "&format=xml", but instead of returning xml it returns only blank lines.
tony@home:~$ lynx -post-data http://en-wikipedia.org/w/api.php action=login&lgname=USERNAME&lgpassword=PASSWORD --- You are looking at the HTML representation of the XML format. HTML is good for debugging, but probably is not suitable for your application. See [1]complete documentation, or [2]API help for more information. <?xml version="1.0"?> <api> <login result="Success" lguserid="XXX" lgusername="USERNAME" lgtoken="TOKEN" cookieprefix="enwiki" sessionid="SESSIONID" /> </api>
References
1. http://www.mediawiki.org/wiki/API 2. http://en.wikipedia.org/w/api.php
tony@home:~$ lynx -post-data http://en-wikipedia.org/w/api.php action=login&lgname=USERNAME&lgpassword=PASSWORD&format=xml ---
tony@home:~$
I tried this on my own box, and it worked for me:
roan@roanLaptop:~/mediawiki$ wget http://en.wikipedia.org/w/api.php '--post-data=action=login&lgname=Catrope&lgpassword=Whee&format=xml'
roan@roanLaptop:~/mediawiki$ cat api.php <?xml version="1.0"?><api><login result="WrongPass" /></api>roan@roanLaptop:~/mediawiki$
roan@roanLaptop:~/mediawiki$ wget http://en.wikipedia.org/w/api.php '--post-data=action=login&lgname=Catrope&lgpassword=myrealpassword&format=xml'
roan@roanLaptop:~/mediawiki$ cat api.php <?xml version="1.0"?><api><login result="Success" lguserid="4587601" lgusername="Catrope" lgtoken="01d2a06cc88aaac0e302b6919838da56" cookieprefix="enwiki" sessionid="8db0e034f8eca59183d604ba34fd96fa" /></api>roan@roanLaptop:~/mediawiki$
Roan Kattouw (Catrope)
Tony Sidaway wrote:
The following is a shell session using the lynx browser to illustrate the problem. Sensitive data has been blanked out. The second browser invocation is identical to the first except for "&format=xml", but instead of returning xml it returns only blank lines.
tony@home:~$ lynx -post-data http://en-wikipedia.org/w/api.php action=login&lgname=USERNAME&lgpassword=PASSWORD
You are looking at the HTML representation of the XML format. HTML is good for debugging, but probably is not suitable for your application. See [1]complete documentation, or [2]API help for more information.
<?xml version="1.0"?>
<api> <login result="Success" lguserid="XXX" lgusername="USERNAME" lgtoken="TOKEN" cookieprefix="enwiki" sessionid="SESSIONID" /> </api>
References
tony@home:~$ lynx -post-data http://en-wikipedia.org/w/api.php action=login&lgname=USERNAME&lgpassword=PASSWORD&format=xml
tony@home:~$
& is a special character for the shell. Are you quoting it? (the easiest way, placing single quotes around the text) If you posted on the second invocation to en-wikipedia.org instead of en.wikipedia.org that could matter, too.
mediawiki-api@lists.wikimedia.org