SSL error with Python requests despite up-to-date dependencies

后端 未结 3 427
天涯浪人
天涯浪人 2020-11-30 05:50

I am getting an SSL \"bad handshake\" error. Most similar responses to this problem seem to stem from old libraries, 1024bit cert. incompatibility, etc... I think

相关标签:
3条回答
  • 2020-11-30 06:36

    The validation fails because the server you access is setup improperly, i.e. it is not a fault of your setup or code. Looking at the report from SSLLabs you see

    This server's certificate chain is incomplete. Grade capped to B.

    This means that the server sends a certificate chain which is missing an intermediate certificate to the trusted root and thus your client can not build the trust chain. Most desktop browsers work around this problem by trying to get the missing certificate from somewhere else but normal TLS libraries will fail in this case. You would need to explicitly add the missing chain certificate as trusted to work around this problem:

    import requests
    requests.get('https://api.sidecar.io', verify = 'mycerts.pem')
    

    mycerts.pem should contain the missing intermediate certificate and the trusted root certificate. A tested version for mycerts.pem can be found in http://pastebin.com/aZSKfyb7.

    0 讨论(0)
  • 2020-11-30 06:36

    This may help as workaround for your issue.

    print(requests.get(url, proxies,verify = False))
    
    0 讨论(0)
  • 2020-11-30 06:54

    I fixed it using the python-certifi-win32 package:

    pip install python-certifi-win32
    

    or with anaconda

    conda install -c conda-forge python-certifi-win32
    

    then you can use:

    requests.get(url)
    #or
    requests.get(url, verify=True)
    

    and the certificate is checked using the Windows Certificate Store.

    This only works if the certificate is installed in the Windows Certificate Store.

    0 讨论(0)
提交回复
热议问题