解决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 paramiko模块的使用示例
Apr 11 Python
django celery redis使用具体实践
Apr 08 Python
详解python中的hashlib模块的使用
Apr 22 Python
python连接、操作mongodb数据库的方法实例详解
Sep 11 Python
详解python破解zip文件密码的方法
Jan 13 Python
基于Tensorflow的MNIST手写数字识别分类
Jun 17 Python
解决python 虚拟环境删除包无法加载的问题
Jul 13 Python
python调用摄像头的示例代码
Sep 28 Python
python爬虫中url管理器去重操作实例
Nov 30 Python
python中append函数用法讲解
Dec 11 Python
selenium自动化测试入门实战
Dec 21 Python
python批量更改目录名/文件名的方法
Apr 18 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
php setcookie函数的参数说明及其用法
2014/04/20 PHP
PHP三元运算的2种写法代码实例
2014/05/12 PHP
PHP堆栈调试操作简单示例
2018/06/15 PHP
解决PhpStorm64不能启动的问题
2020/06/20 PHP
浅谈jquery中delegate()与live()
2015/06/22 Javascript
javascript中对变量类型的判断方法
2015/08/09 Javascript
谈一谈jQuery核心架构设计
2016/03/28 Javascript
IE8 内存泄露(内存一直增长 )的原因及解决办法
2016/04/06 Javascript
BootStrap智能表单实战系列(八)表单配置json详解
2016/06/13 Javascript
Bootstrap学习系列之使用 Bootstrap Typeahead 组件实现百度下拉效果
2016/07/07 Javascript
封装的dialog插件 基于bootstrap模态对话框的简单扩展
2016/08/10 Javascript
JavaScript中自带的 reduce()方法使用示例详解
2016/08/10 Javascript
JS实现拖动滚动条评分的效果代码分享
2016/09/29 Javascript
JS获取浮动(float)元素的style.left值为空的快速解决办法
2017/02/19 Javascript
WebSocket实现简单客服聊天系统
2017/05/12 Javascript
Bootstrap fileinput文件上传组件使用详解
2017/06/06 Javascript
Node.js如何实现注册邮箱激活功能 (常见)
2017/07/23 Javascript
Vue.js中关于侦听器(watch)的高级用法示例
2018/05/02 Javascript
老生常谈JS中的继承及实现代码
2018/07/06 Javascript
React 路由懒加载的几种实现方案
2018/10/23 Javascript
jquery html添加元素/删除元素操作实例详解
2020/05/20 jQuery
python中的yield使用方法
2014/02/11 Python
使用Python装饰器在Django框架下去除冗余代码的教程
2015/04/16 Python
Django自定义插件实现网站登录验证码功能
2017/04/19 Python
基于Python 装饰器装饰类中的方法实例
2018/04/21 Python
详解pandas DataFrame的查询方法(loc,iloc,at,iat,ix的用法和区别)
2019/08/02 Python
pytorch中的weight-initilzation用法
2020/06/24 Python
Python包资源下载路径报404解决方案
2020/11/05 Python
HTML5 拖拽批量上传文件的示例代码
2018/03/28 HTML / CSS
世界各地的旅游、观光和活动:Isango!
2019/10/29 全球购物
瑞典在互联网上最大的宠物商店:Animail
2020/10/31 全球购物
应届毕业生自我评价分享
2013/12/15 职场文书
医学求职信
2014/05/28 职场文书
2014年安全生产工作总结
2014/11/13 职场文书
2015年检验员工作总结范文
2015/04/30 职场文书
TV动画「神渣☆爱豆」公开第一弹主视觉图
2022/03/21 日漫