I want to use mwclient to edit an internal wiki behind HTTPS. This page suggests that you can pass in a host tuple like this:
site = mwclient.Site((‘https’,’wiki.whatever.com’))
However I don’t see how to authenticate with Apache. Do you need to set up a urllib2 opener handler with the authentication?
A solution that works with python-wikitools would alternatively be welcome, but also has a lack of https examples.
Update:
Perhaps it uses the same user ID and password as you’re using to login to the wiki? I still get an error in that case though:
Traceback (most recent call last):
File "C:\ddc\DDC_Toolbox\python_root\apps\create_new_project\trunk\create_new_project.py", line 36, in <module>
site = mwclient.Site(('https',url))
File "C:\bin\Python27\lib\site-packages\mwclient-0.6.5-py2.7.egg\mwclient\client.py", line 92, in __init__
self.site_init()
File "C:\bin\Python27\lib\site-packages\mwclient-0.6.5-py2.7.egg\mwclient\client.py", line 100, in site_init
siprop = 'general|namespaces', uiprop = 'groups|rights')
File "C:\bin\Python27\lib\site-packages\mwclient-0.6.5-py2.7.egg\mwclient\client.py", line 165, in api
info = self.raw_api(action, **kwargs)
File "C:\bin\Python27\lib\site-packages\mwclient-0.6.5-py2.7.egg\mwclient\client.py", line 248, in raw_api
json_data = self.raw_call('api', data).read()
File "C:\bin\Python27\lib\site-packages\mwclient-0.6.5-py2.7.egg\mwclient\client.py", line 223, in raw_call
url, data = data, headers = headers)
File "C:\bin\Python27\lib\site-packages\mwclient-0.6.5-py2.7.egg\mwclient\http.py", line 226, in post
path, headers, data)
File "C:\bin\Python27\lib\site-packages\mwclient-0.6.5-py2.7.egg\mwclient\http.py", line 161, in post
return self.request('POST', host, path, headers, data)
File "C:\bin\Python27\lib\site-packages\mwclient-0.6.5-py2.7.egg\mwclient\http.py", line 152, in request
raise errors.HTTPStatusError, (res.status, res)
mwclient.errors.HTTPStatusError: (401, <httplib.HTTPResponse instance at 0x0241C0D0>)
Well,
mwclientdoesn’t use urllib2, so installing an urllib2 AuthHandler won’t do anything.It’s using
httplib, and from a quick look at the source, there seems to be no way to add your own headers to the requests sent by the library, so adding a custom Authorization header won’t work without modifying the library itself.python-wikitoolson the other hand usesurllib2, but instantiates it’s own opener, and to be able to add an auth handler to that, you’d also need to modify the library-So, unfortunately both apis don’t allow you to use authentication out of the box.