Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get Python requests to trust a self signed SSL certificate?

import requests data = {'foo':'bar'} url = 'https://foo.com/bar' r = requests.post(url, data=data) 

If the URL uses a self signed certificate, this fails with

requests.exceptions.SSLError: [Errno 1] _ssl.c:507: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed 

I know that I can pass False to the verify parameter, like this:

r = requests.post(url, data=data, verify=False) 

However, what I would like to do is point requests to a copy of the public key on disk and tell it to trust that certificate.

like image 382
Matthew Moisen Avatar asked May 22 '15 21:05

Matthew Moisen


People also ask

How do I force a certificate trust?

You must manually turn on trust for SSL/TLS when you install a profile that is sent to you via email or downloaded from a website. If you want to turn on SSL/TLS trust for that certificate, go to Settings > General > About > Certificate Trust Settings.

Does Python requests use certifi?

Requests verifies SSL certificates for HTTPS requests, just like a web browser. SSL Certificates are small data files that digitally bind a cryptographic key to an organization's details.


1 Answers

try:

r = requests.post(url, data=data, verify='/path/to/public_key.pem') 
like image 78
krock Avatar answered Sep 21 '22 09:09

krock