美文网首页
Python-requests的使用 - SSL证书验证

Python-requests的使用 - SSL证书验证

作者: Koelre | 来源:发表于2018-08-04 21:51 被阅读1204次

    对于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)
    

    相关文章

      网友评论

          本文标题:Python-requests的使用 - SSL证书验证

          本文链接:https://www.haomeiwen.com/subject/jixopftx.html