requests的SSL证书验证
_Miya 人气:3requests的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证书的加密认证
以上为个人经验,希望能给大家一个参考,也希望大家多多支持。
加载全部内容