当前位置:主页 > 软件编程 > Python代码 >

Python requests的SSL证书验证方式

时间:2022-08-19 09:52:17 | 栏目:Python代码 | 点击:

requests的SSL证书验证

1、对于HTTPS

默认情况下,启用SSL验证,如果无法验证SSL证书会导致:

requests.exceptions.SSLError: ("bad handshake: Error([('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')],)",)

解决办法:

# 在requests中加入verify=False
res = requests.get(ur,verify=False)

2、以上步骤后,会出现警告

InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings InsecureRequestWarning)

解决办法:

 from requests.packages.urllib3.exceptions import InsecureRequestWarning
# 禁用安全请求警告
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)

requests处理不信任的ssl证书

不验证ssl证书

requests.get(url,verify=False)

以前的12306证书不被认证

对于https协议

会有一个ssl证书的加密认证

您可能感兴趣的文章:

相关文章