解决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实现字典依据value排序
Feb 24 Python
python使用tensorflow深度学习识别验证码
Apr 03 Python
DataFrame中的object转换成float的方法
Apr 10 Python
Python 编程速成(推荐)
Apr 15 Python
Python批量生成幻影坦克图片实例代码
Jun 04 Python
python使用正则表达式去除中文文本多余空格,保留英文之间空格方法详解
Feb 11 Python
python异常处理、自定义异常、断言原理与用法分析
Mar 23 Python
jupyter notebook tensorflow打印device信息实例
Apr 20 Python
Python requests.post方法中data与json参数区别详解
Apr 30 Python
python查看矩阵的行列号以及维数方式
May 22 Python
python opencv常用图形绘制方法(线段、矩形、圆形、椭圆、文本)
Apr 12 Python
Python实现日志实时监测的示例详解
Apr 06 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
phpQuery让php处理html代码像jQuery一样方便
2015/01/06 PHP
PHP内置加密函数详解
2016/11/20 PHP
php+js实现百度地图多点标注的方法
2016/11/30 PHP
PHP PDOStatement::debugDumpParams讲解
2019/01/30 PHP
兼容ie和firefox js关闭代码
2008/12/11 Javascript
加载jQuery后$冲突的解决办法
2010/07/09 Javascript
javascript控制swfObject应用介绍
2012/11/29 Javascript
jQuery中$.fn的用法示例介绍
2013/11/05 Javascript
ECMAScript6函数默认参数
2015/06/12 Javascript
基于jQuery实现的向下滑动二级菜单效果代码
2015/08/31 Javascript
全面解析Bootstrap表单样式的使用
2016/09/09 Javascript
基于JS分页控件实现简单美观仿淘宝分页按钮效果
2016/11/07 Javascript
JS判断键盘是否按的回车键并触发指定按钮点击操作的方法
2017/02/13 Javascript
BootStrap与Select2使用小结
2017/02/17 Javascript
React组件之间的通信的实例代码
2017/06/27 Javascript
javascript 缓冲运动框架的实现
2017/09/29 Javascript
详解js访问对象的属性和方法
2018/10/25 Javascript
vue 使用axios 数据请求第三方插件的使用教程详解
2019/07/05 Javascript
原生js实现二级联动菜单
2019/11/27 Javascript
js实现的订阅发布者模式简单示例
2020/03/14 Javascript
Python加pyGame实现的简单拼图游戏实例
2015/05/15 Python
PyQt5内嵌浏览器注入JavaScript脚本实现自动化操作的代码实例
2019/02/13 Python
mac系统下Redis安装和使用步骤详解
2019/07/09 Python
Django框架视图介绍与使用详解
2019/07/18 Python
使用python实现数组、链表、队列、栈的方法
2019/12/20 Python
Eclipse配置python默认头过程图解
2020/04/26 Python
python语言是免费还是收费的?
2020/06/15 Python
使用python编写一个语音朗读闹钟功能的示例代码
2020/07/14 Python
优秀应届毕业生自荐信
2013/11/16 职场文书
会议活动邀请函
2014/01/27 职场文书
文科生自我鉴定
2014/02/15 职场文书
音乐幼师求职信
2014/07/09 职场文书
小学生校园广播稿
2014/09/28 职场文书
求职导师推荐信范文
2015/03/27 职场文书
React + Threejs + Swiper 实现全景图效果的完整代码
2021/06/28 Javascript
js 数组 fill() 填充方法
2021/11/02 Javascript