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

前端 未结 7 2089
故里飘歌
故里飘歌 2020-11-27 15:07
import requests
data = {\'foo\':\'bar\'}
url = \'https://foo.com/bar\'
r = requests.post(url, data=data)

If the URL uses a self signed certificate,

7条回答
  •  眼角桃花
    2020-11-27 15:37

    Incase anyone happens to land here (like I did) looking to add a CA (in my case Charles Proxy) for httplib2, it looks like you can append it to the cacerts.txt file included with the python package.

    For example:

    cat ~/Desktop/charles-ssl-proxying-certificate.pem >> /usr/local/google-cloud-sdk/lib/third_party/httplib2/cacerts.txt
    

    The environment variables referenced in other solutions appear to be requests-specific and were not picked up by httplib2 in my testing.

提交回复
热议问题