Try:
r = requests.post(url, data=data, verify='/path/to/public_key.pem')
Answer from krock on Stack OverflowTry:
r = requests.post(url, data=data, verify='/path/to/public_key.pem')
The easiest is to export the variable REQUESTS_CA_BUNDLE that points to your private certificate authority, or a specific certificate bundle. On the command line you can do that as follows:
export REQUESTS_CA_BUNDLE=/path/to/your/certificate.pem
python script.py
If you have your certificate authority and you don't want to type the export each time you can add the REQUESTS_CA_BUNDLE to your ~/.bash_profile as follows:
echo "export REQUESTS_CA_BUNDLE=/path/to/your/certificate.pem" >> ~/.bash_profile ; source ~/.bash_profile
Python Requests and self-signed SSL certs
requests uses urlllib3, which passes None by default to ssl.wrap_socket. The default is set by create_default_context which calls load_default_certs which calls set_default_verify_paths which has the following documentation:
Load a set of default “certification authority” (CA) certificates from a filesystem path defined when building the OpenSSL library. Unfortunately, there’s no easy way to know whether this method succeeds: no error is returned if no certificates are to be found. When the OpenSSL library is provided as part of the operating system, though, it is likely to be configured properly.
In conclusion, I have no idea.
More on reddit.comGet a self-signed client certificate on the server side
Self signed certificate, passed to via verify=/path/to/cert does still trigger certificate verify failed
[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self-signed certificate in certificate chain
Videos
I am working on talking to my server via https with Python Requests. I have a self signed cert on the box the client is running on. When i do the following
r = requests.request(http_method, http_url, data=payload, headers=kwargs['headers'], verify='/etc/ssl/certs/mycert.pem')
Everything works perfect! YAY!!! BUT, I do not want to have to provide a path to verify, as this program will be talking from multiple clients to multiple servers. So it has to be dynamic. I have installed the self-signed cert on my box using ca-certificates. I can view the certificate in /etc/ssl/certs/ no problem. I can run openssl to dump the cert and it's fine. I can provide the path as shown above and it works. How can I tell requests to look at and honor the trusted certs on my box?