解决Python requests 报错方法集锦


Posted in Python onMarch 19, 2017

python版本和ssl版本都会导致 requests在请求https网站时候会出一些错误,最好使用新版本。

1 Python2.6x use requests

一台老Centos机器上跑着古老的应用,加了一个新模块之后报错 报错 InsecurePlatformWarning: A true SSLContext object is not available.

/usr/lib/python2.6/site-packages/requests/packages/urllib3/util/ssl_.py:132: 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

解决办法

使用老版本的 requests

$pip install requests==2.5.3

或者这样安装

$ pip install requests[security]

2 SSL3_GET_SERVER_CERTIFICATE:certificate verify failed

错误如下 版本 python2.7.5

Traceback (most recent call last):
  File "./test.py", line 24, in <module>
  response = requests.get(url1, headers=headers)
  File "build/bdist.linux-x86_64/egg/requests/api.py", line 52, in get
  File "build/bdist.linux-x86_64/egg/requests/api.py", line 40, in request
  File "build/bdist.linux-x86_64/egg/requests/sessions.py", line 209, in request
  File "build/bdist.linux-x86_64/egg/requests/models.py", line 624, in send
  File "build/bdist.linux-x86_64/egg/requests/models.py", line 300, in _build_response
  File "build/bdist.linux-x86_64/egg/requests/models.py", line 611, in send
requests.exceptions.SSLError: [Errno 1] _ssl.c:503: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed

解决方法

可以禁用 verify

>>> requests.get('https://google.com', verify=True)
问题地址 python-requests-throwing-up-sslerror

3 SSLError: bad handshake

SSLError: bad handshake: Error([(‘SSL routines', ‘SSL3_GET_SERVER_CERTIFICATE', ‘certificate verify failed')],) python2.7.5
pip uninstall -y certifi && pip install certifi==2015.04.28

讨论参见: https://github.com/rackspace/pyrax/issues/601

以上所述是小编给大家介绍的Python requests 报错方法集锦,希望对大家有所帮助,如果大家有任何疑问欢迎给我留言,小编会及时回复大家的!

Python 相关文章推荐
python获取Linux下文件版本信息、公司名和产品名的方法
Oct 05 Python
python中import学习备忘笔记
Jan 24 Python
python实现简单中文词频统计示例
Nov 08 Python
TensorFLow用Saver保存和恢复变量
Mar 10 Python
python自动截取需要区域,进行图像识别的方法
May 17 Python
Python图像处理之简单画板实现方法示例
Aug 30 Python
Django migrations 默认目录修改的方法教程
Sep 28 Python
使用Py2Exe for Python3创建自己的exe程序示例
Oct 31 Python
Python CVXOPT模块安装及使用解析
Aug 01 Python
Pytorch 计算误判率,计算准确率,计算召回率的例子
Jan 18 Python
pycharm设置python文件模板信息过程图解
Mar 10 Python
python实现三种随机请求头方式
Jan 05 Python
python字符串str和字节数组相互转化方法
Mar 18 #Python
Python执行时间的计算方法小结
Mar 17 #Python
python django事务transaction源码分析详解
Mar 17 #Python
Python自动生产表情包
Mar 17 #Python
Python实现的异步代理爬虫及代理池
Mar 17 #Python
Python 专题一 函数的基础知识
Mar 16 #Python
python 专题九 Mysql数据库编程基础知识
Mar 16 #Python
You might like
解密ThinkPHP3.1.2版本之模块和操作映射
2014/06/19 PHP
php获取linux命令结果的实例
2017/03/13 PHP
自制PHP框架之路由与控制器
2017/05/07 PHP
php实现微信支付之企业付款
2018/05/30 PHP
基于jQuery的表格操作插件
2010/04/22 Javascript
JS刷新框架外页面七种实现代码
2013/02/18 Javascript
Struts2的s:radio标签使用及用jquery添加change事件
2013/04/08 Javascript
JS实现自定义简单网页软键盘效果代码
2015/11/05 Javascript
jQuery实现的导航动画效果(附demo源码)
2016/04/01 Javascript
详解weex默认webpack.config.js改造
2018/01/08 Javascript
JavaScript中import用法总结
2019/01/20 Javascript
js实现一个页面多个倒计时的3种方法
2019/02/25 Javascript
vue中nextTick用法实例
2019/09/11 Javascript
vue项目在线上服务器访问失败原因分析
2020/08/14 Javascript
[01:30]我们共输赢 完美世界城市挑战赛开启全新赛季
2019/04/19 DOTA
操作Windows注册表的简单的Python程序制作教程
2015/04/07 Python
给Python中的MySQLdb模块添加超时功能的教程
2015/05/05 Python
Python使用cx_Oracle模块将oracle中数据导出到csv文件的方法
2015/05/16 Python
详解Django框架中的视图级缓存
2015/07/23 Python
解决Django一个表单对应多个按钮的问题
2019/07/18 Python
Python基于pandas绘制散点图矩阵代码实例
2020/06/04 Python
Python延迟绑定问题原理及解决方案
2020/08/04 Python
python3从网络摄像机解析mjpeg http流的示例
2020/11/13 Python
OpenCV+python实现膨胀和腐蚀的示例
2020/12/21 Python
CSS3实现多背景模拟动态边框的效果
2016/11/08 HTML / CSS
H5 canvas实现贪吃蛇小游戏
2017/07/28 HTML / CSS
SEPHORA新西兰官方网站:购买化妆品和护肤品
2016/12/02 全球购物
大整数数相乘的问题
2012/07/22 面试题
介绍一下Java中的static关键字
2012/05/12 面试题
读书心得体会
2013/12/28 职场文书
2014年应届大学生毕业自我鉴定
2014/01/31 职场文书
股东合作协议书
2014/04/14 职场文书
法人授权委托书公证范本
2014/09/14 职场文书
公司优秀员工推荐信
2015/03/24 职场文书
质量整改通知单
2015/04/21 职场文书
MySQL 四种连接和多表查询详解
2021/07/16 MySQL