Python Requests throwing SSLError

前端 未结 24 3143
小蘑菇
小蘑菇 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:25

    As pointed out by others, this problem "is caused by an untrusted SSL certificate". My answer is based on the top-rated answer and this answer.

    You can test the certificate using curl:

    curl -vvI https://example.com
    

    If an error returns, you have 3 options:

    1. For a quick fix, you could just not verify the certificate:
    requests.get('https://example.com', verify=False)
    
    1. Pass the path to the CA_BUNDLE file or directory with certificates of trusted CAs:
    requests.get('https://example.com', verify='/path/to/certfile')
    
    1. If you have access to, fix the web server certificate.

    My problem was because I was using only my site's certificate, not the intermediate (a.k.a. chain) certificate.

    If you are using Let's Encrypt, you should use the fullchain.pem file, not cert.pem.

提交回复
热议问题