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

前端 未结 7 2098
故里飘歌
故里飘歌 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:35

    Case where multiple certificates are needed was solved as follows: Concatenate the multiple root pem files, myCert-A-Root.pem and myCert-B-Root.pem, to a file. Then set the requests REQUESTS_CA_BUNDLE var to that file in my ./.bash_profile.

    $ cp myCert-A-Root.pem ca_roots.pem
    $ cat myCert-B-Root.pem >> ca_roots.pem
    $ echo "export REQUESTS_CA_BUNDLE=~/PATH_TO/CA_CHAIN/ca_roots.pem" >> ~/.bash_profile ; source ~/.bash_profile
    

提交回复
热议问题