Python使用requests模块访问HTTPS网站报错`certificate verify failed` 使用requests模块访问HTTPS网站报错:
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. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#snimissingwarning.
SNIMissingWarning
/data1/sleep/env/lib/python2.7/site-packages/requests/packages/urllib3/util/ssl_.py:120: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning.
InsecurePlatformWarning
Traceback (most recent call last):
File "test_demo1.py", line 16, in
f()
File "test_demo1.py", line 13, in f
r=requests.post(url,json=data,headers=header,)
File "/data1/env/lib/python2.7/site-packages/requests/api.py", line 107, in post
return request('post', url, data=https://www.it610.com/article/data, json=json, **kwargs)
File"/data1/env/lib/python2.7/site-packages/requests/api.py", line 53, in request
return session.request(method=method, url=url, **kwargs)
File "/data1/env/lib/python2.7/site-packages/requests/sessions.py", line 468, in request
resp = self.send(prep, **send_kwargs)
File "/data1/env/lib/python2.7/site-packages/requests/sessions.py", line 576, in send
r = adapter.send(request, **kwargs)
File "/data1/env/lib/python2.7/site-packages/requests/adapters.py", line 447, in send
raise SSLError(e, request=request)
requests.exceptions.SSLError: [Errno 1] _ssl.c:499: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed
【Python使用requests模块访问HTTPS网站报错`certificate verify failed`】看到两个警告,查看警告提供的网站发现,是因为在2.7.9之前的Python版本,urllib3的ssl比较旧,就会导致这个错。
解决方法是安装
urllib3[secure]
,也就是带安全模块的urllib3.pip install urllib3[secure]
#如果装得很慢,就使用豆瓣的pip源
pip install -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com
#如果报错不支持参数--trusted-host,就升级pip
pip install --upgrade pip
安装后,一般就可以访问了。
如果还是不行,就要重新安装requests模块
pip uninstall requests
pip installrequests
推荐阅读
- 推荐系统论文进阶|CTR预估 论文精读(十一)--Deep Interest Evolution Network(DIEN)
- Python专栏|数据分析的常规流程
- Python|Win10下 Python开发环境搭建(PyCharm + Anaconda) && 环境变量配置 && 常用工具安装配置
- Python绘制小红花
- Pytorch学习|sklearn-SVM 模型保存、交叉验证与网格搜索
- OpenCV|OpenCV-Python实战(18)——深度学习简介与入门示例
- python|8. 文件系统——文件的删除、移动、复制过程以及链接文件
- 爬虫|若想拿下爬虫大单,怎能不会逆向爬虫,价值过万的逆向爬虫教程限时分享
- 分布式|《Python3网络爬虫开发实战(第二版)》内容介绍
- java|微软认真聆听了开源 .NET 开发社区的炮轰( 通过CLI 支持 Hot Reload 功能)