[Fusionforge-general] SOLVED Re: Interfacing with the MediaWiki API ?

Olivier Berger olivier.berger at telecom-sudparis.eu
Tue Mar 25 17:47:57 CET 2014


Responding to myself.

Olivier Berger <olivier.berger at telecom-sudparis.eu> writes:

> Olivier Berger <olivier.berger at telecom-sudparis.eu> writes:
>
>> Olivier Berger <olivier.berger at telecom-sudparis.eu> writes:
>>
>>>
>>> AFAICT, this works well, and the login succeeds :-)
>>>
>>
>> Hmm... but it doesn't go any further :-/
>>
>> The login 2 steps are performing OK, and it seems the cookies are set,
>> but then, the next query fails :
>> api.php?action=query&meta=siteinfo&maxlag=120&siprop=general%7Cnamespaces%7Cnamespacealiases&format=json
>> gets :
>> readapidenied, You need read permission to use this module
>>
>
> My understanding is that even though the user seems to be logged in
> correctly via the action=login API invocation, and thus the MW cookies
> set, this next action=query won't work, unless the wiki is configured in
> fusionforge roles, so that anonymous users can read it...
>
> So, it looks like the api doesn't detect the logged-in user for the read
> permissions... Maybe it expects all wikis to be publicly readable, or
> there is a bug...
>
> I'll have to dig the mediawiki api code, I guess.
>

I've worked more in this, and succeded calling the API even on a
protected project's mediawiki.

The read permission issue happened because the fusionforge session
wasn't recognized during the session cookie retrieval : the associated
checks tried to match the correct User-Agent, which failed because of a
bug in the wikitools Python library [0] I used.

Now, by performing a scripted fusionforge login, and keeping the session
cookie, the calls to the API work as expected, i.e. basic operations
that only need a read permission work.

For reference, I'm attaching the Python script that demonstrates this.

Note that the bug in wikitools 1.1.1 needs this patch for a fix :
--- api.py.orig	2014-03-25 16:39:02.176199937 +0100
+++ api.py	2014-03-25 16:39:16.080168172 +0100
@@ -75,7 +75,7 @@
 				"Content-Type": "application/x-www-form-urlencoded",
 				"Content-Length": len(self.encodeddata)
 			}
-		self.headers["User-agent"] = wiki.useragent,
+		self.headers["User-agent"] = wiki.useragent
 		if gzip:
 			self.headers['Accept-Encoding'] = 'gzip'
 		self.wiki = wiki


/me happy :-) Next steps will be scripting page imports through API.

Feel free to ask for more details.

Best regards,

-------------- next part --------------
A non-text attachment was scrubbed...
Name: fusionforge.py
Type: text/x-python
Size: 4721 bytes
Desc: not available
URL: <http://lists.fusionforge.org/pipermail/fusionforge-general/attachments/20140325/cdeeb309/attachment.py>
-------------- next part --------------

[0] https://pypi.python.org/pypi/wikitools
-- 
Olivier BERGER 
http://www-public.telecom-sudparis.eu/~berger_o/ - OpenPGP-Id: 2048R/5819D7E8
Ingenieur Recherche - Dept INF
Institut Mines-Telecom, Telecom SudParis, Evry (France)


More information about the Fusionforge-general mailing list