Python-requests的使用 - SSL证书验证 - 简书
2019-08-18 14:23:10 Author: www.jianshu.com(查看原文) 阅读量:403 收藏

对于HTTPS,默认情况下,启用SSL验证,如果无法验证SSL证书,将会引发SSLError,不做处理就会如1所示,酱紫的:
1、requests.exceptions.SSLError: ("bad handshake: Error([('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')],)",)
解决办法:

    # 在requests中加入这个 忽略SSL证书 verify=False
    url = "https://www.baidu.com/"
    res = requests.get(url,timeout=30,verify=False).content
    print res

2、自步骤1之后,会出现 酱紫的 警告: C:\Python27\lib\site-packages\urllib3\connectionpool.py:852: 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)

文章来源: https://www.jianshu.com/p/82fb062de950
如有侵权请联系:admin#unsafe.sh