This is not a duplicate for this post. I tried the solutions there and nothing works in my case.
I am using Windows and Python 3.6.5. I have a python script for a TLS c
This question has been idle for a while, but in case somebody is still struggling with connecting to a server with a self-signed certificate via Python ssl
library:
You can use the load_verify_locations
method of SSLContext
to specify custom self-signed root certs (see Python Docs for load_verify_locations).
The forementioned code could be extended as follows:
...
context = ssl.SSLContext()
context.verify_mode = ssl.CERT_OPTIONAL
context.check_hostname = False
context.load_verify_locations(cafile='/path/to/your/cacert.pem')
...
Be aware that you also need to include public root certs in case you want to connect to other servers with public certificates with the same client/context. (you could for example append your cacert.pem
content to the certifi root certificates and reference that folder / path instead).
See also this Python docs paragraph for more information: client-side operations.