pythonproxydokuwiki

How to use proxy server with dokuwiki module in python


I am trying to write an application to easy my HP disk replacement procedure for work.

We use dokuwiki for tracking cases and I would like to implement it with python so it would be done automatically when replacing a disk. Unfortunately we have to use a proxy to reach the dokuwiki link and I cannot find a way to use it whilst inside python.

So when I am trying to run the following in python IDE I always get an error even though I have set up the http/https_proxy inside venv as well.

In [20]: wiki = dokuwiki.DokuWiki('https://172.xx.xx.xx/doku.php?id=xx:xx', 'username', 'password')

I expect no errors when running the command but I get the following:

SSLCertVerificationError Traceback (most recent call last) in ----> 1 wiki = dokuwiki.DokuWiki('https://172.xx.xx.xx/doku.php?id=xx:xx', 'username', 'password') ...... ......

.....

SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate (_ssl.c:1056)


Solution

  • SSL certificates are issued and verified against a FQDN (Fully Qualified Domain Name) so if you use https with an IP address, the certificate can't be verified. If you can, access you're wiki through the FQDN and ensure the certificate is valid.

    Otherwise you can disable the verification of the certificate (not really a good security practice). As extra parameters are directly passed to the xmlrpc.client.ServerProxy object, something like this should work:

    import dokuwiki
    import ssl
    
    wiki = dokuwiki.DokuWiki('https://172.xx.xx.xx', 'username', 'password', context=ssl._create_unverified_context())
    

    Note: The dokuwiki module also append the XMLRPC URI (/lib/exe/xmlrpc.php) itself so the /doku.php?id=xx:xx part is not necessary.