montonero
montonero

Reputation: 802

How to ignore SSL Certificate Name Mismatch in Python (xmlrpc)

Whilst trying to communicate with a server by using Python's XML-RPC library:

import xmlrpc.client
url = 'https://12345/'

api = xmlrpc.client.ServerProxy(url)
print(api.system.listMethods())

I am getting this error:

ssl.py  in match_hostname ssl.CertificateError: hostname '12345' doesn't match '*.hostname.com'

Obviously, I can alter the source of ssl.py to ignore this, but is there a better way like a parameter I can set etc?

Upvotes: 3

Views: 2900

Answers (2)

Pathim
Pathim

Reputation: 51

A current version of python has an additional context parameter that can use a custom SSL context:

import xmlrpc.client
import ssl
url = 'https://12345/'

api = xmlrpc.client.ServerProxy(url,context=ssl._create_unverified_context())
print(api.system.listMethods())

Upvotes: 5

montonero
montonero

Reputation: 802

There is no such setting in xmlrpc library for obvious reasons. Thus the only way to accomplish this is to remove validation from ssl.py.

Note: I was writing a real world system that would communicate with an external provider via HTTPS. But before we were able to put it live we had to test with their dev-server, which had different hostname hence the certificate error. So there was no security risk as only dev-server credentials were used and some dummy data.

Upvotes: 2

Related Questions