python's requests certificate problems

When https site with requests package requests, we occasionally encounter certificate problems. That is common SSLerror, encounter this problem Mo Mo panic panic.

 

Here there is no suitable site to report the error to find the SSL certificate, so I pretended to request a https site, and then reported to the SSLerror, and then following is the solution

1, you can turn off validation ssl certificates directly

import requests
'''
    :param proxies: (optional) Dictionary mapping protocol to the URL of the proxy.
    :param verify: (optional) Either a boolean, in which case it controls whether we verify
            the server's TLS certificate, or a string, in which case it must be a path
            to a CA bundle to use. Defaults to ``True``.
            
'''

r = requests.get('https://kyfw.12306.cn',verify=False)

print(r.text)

This increase directly as Ture or False to verify change in the function inside, because both for the request () function, so get all the same post with the post and get called.

If this is the way it worked this way, if it does not work with one of the following

import requests
'''
    :param verify: (optional) Either a boolean, in which case it controls whether we verify
            the server's TLS certificate, or a string, in which case it must be a path
            to a CA bundle to use. Defaults to ``True``.
            
'''
## 证书路径
cert = '../cert/test.pem'

r = requests.get('https://kyfw.12306.cn',verify=cert)
print(r.text)

On this, directly to the left to the certificate path verify, you can request

 

Guess you like

Origin www.cnblogs.com/dflblog/p/11465044.html