Python Requests throwing SSLError

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

    The problem you are having is caused by an untrusted SSL certificate.

    Like @dirk mentioned in a previous comment, the quickest fix is setting verify=False:

    requests.get('https://example.com', verify=False)
    

    Please note that this will cause the certificate not to be verified. This will expose your application to security risks, such as man-in-the-middle attacks.

    Of course, apply judgment. As mentioned in the comments, this may be acceptable for quick/throwaway applications/scripts, but really should not go to production software.

    If just skipping the certificate check is not acceptable in your particular context, consider the following options, your best option is to set the verify parameter to a string that is the path of the .pem file of the certificate (which you should obtain by some sort of secure means).

    So, as of version 2.0, the verify parameter accepts the following values, with their respective semantics:

    • True: causes the certificate to validated against the library's own trusted certificate authorities (Note: you can see which Root Certificates Requests uses via the Certifi library, a trust database of RCs extracted from Requests: Certifi - Trust Database for Humans).
    • False: bypasses certificate validation completely.
    • Path to a CA_BUNDLE file for Requests to use to validate the certificates.

    Source: Requests - SSL Cert Verification

    Also take a look at the cert parameter on the same link.

提交回复
热议问题