Search code examples
pythonhttpmediawikiwikipediamwclient

httpError using mwclient with local MediaWiki


I try to create a page using mwclient with a local MediaWiki. With wikipedia.org everything works fine. With my local MediaWiki I enter these commands:

import mwclient
site = mwclient.Site("192.168.1.143")

The result is the following error:

File "/Library/Python/2.7/site-packages/mwclient/http.py", line 152, in request
raise errors.HTTPStatusError, (res.status, res)
mwclient.errors.HTTPStatusError: (404, <httplib.HTTPResponse instance at 0x104368488>)

If I type the IP or the Hostname in my Browser, it works. The same with the ping command.

I used url lib with:

a=urllib.urlopen('http://www.google.com/asdfsf')
a.getcode()

and got the 200 OK Code.

What's the problem here? Any ideas?


Solution

  • The problem is that mwclient expects the api.php (which is what it uses to access the wiki) to be located at /w/, which is the location used for Wikimedia wikis, instead of directly under /, which is the default.

    Per the documentation for Site, you need to use the path parameter for that:

    site = mwclient.Site('192.168.1.143', path='/')