Python Requests throwing SSLError

前端 未结 24 2697
小蘑菇
小蘑菇 2020-11-22 02:49

I\'m working on a simple script that involves CAS, jspring security check, redirection, etc. I would like to use Kenneth Reitz\'s python requests because it\'s a great piec

24条回答
  •  失恋的感觉
    2020-11-22 03:40

    In case you have a library that relies on requests and you cannot modify the verify path (like with pyvmomi) then you'll have to find the cacert.pem bundled with requests and append your CA there. Here's a generic approach to find the cacert.pem location:

    windows

    C:\>python -c "import requests; print requests.certs.where()"
    c:\Python27\lib\site-packages\requests-2.8.1-py2.7.egg\requests\cacert.pem
    

    linux

    #  (py2.7.5,requests 2.7.0, verify not enforced)
    root@host:~/# python -c "import requests; print requests.certs.where()"
    /usr/lib/python2.7/dist-packages/certifi/cacert.pem
    
    #  (py2.7.10, verify enforced)
    root@host:~/# python -c "import requests; print requests.certs.where()"
    /usr/local/lib/python2.7/dist-packages/requests/cacert.pem
    

    btw. @requests-devs, bundling your own cacerts with request is really, really annoying... especially the fact that you do not seem to use the system ca store first and this is not documented anywhere.

    update

    in situations, where you're using a library and have no control over the ca-bundle location you could also explicitly set the ca-bundle location to be your host-wide ca-bundle:

    REQUESTS_CA_BUNDLE=/etc/ssl/certs/ca-bundle.crt python -c "import requests; requests.get('https://somesite.com';)"
    

提交回复
热议问题