disable default certificate verification in python 2.7.8

来源:互联网 发布:严宽乔振宇 知乎 编辑:程序博客网 时间:2024/05/21 19:29

环境:Python 2.7.8
浏览器中访问该网站时会弹出证书不受信任,但是忽略仍可继续访问。
python 中若继续访问时则需关闭SSL 认证请求。在python 2.7.8 中ssl模块并不存在
ssl._create_default_https_context = ssl._create_unverified_context
而需使用另一种方法进行关闭,如下代码所示:

...requests.get(url=url, headers=headers,verify=False)...

只需将verify关闭。
关闭后会有警告信息提示
C:\Python27\lib\site-packages\urllib3\util\ssl_.py:339: SNIMissingWarning: An HTTPS request has been made, but the SNI (Subject Name Indication) extension to TLS is not available on this platform. This may cause the server to present an incorrect TLS certificate, which can cause validation failures. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
SNIMissingWarning
C:\Python27\lib\site-packages\urllib3\util\ssl_.py:137: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
InsecurePlatformWarning
C:\Python27\lib\site-packages\urllib3\connectionpool.py:858: 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)

阅读全文
0 0
原创粉丝点击