解决Python requests 报错方法集锦

作者:lzz957748332 时间:2023-05-05 20:21:27 

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 报错方法集锦,希望对大家有所帮助,如果大家有任何疑问欢迎给我留言,小编会及时回复大家的!

来源:http://blog.csdn.net/orangleliu/article/details/62037768

标签:python,requests
0
投稿

猜你喜欢

  • python实现Adapter模式实例代码

    2021-10-20 00:43:02
  • pytorch中使用LSTM详解

    2021-01-08 04:27:10
  • jfinal与bootstrap的登录跳转实战演习

    2023-07-02 05:20:01
  • 怎样开启phpStudy服务器

    2023-05-25 00:38:06
  • 利用python-pypcap抓取带VLAN标签的数据包方法

    2021-03-15 04:46:20
  • Python构建自动在线刷视频的实现

    2021-12-17 15:53:37
  • Go语言并发技术详解

    2024-02-14 16:49:22
  • python调用文字识别OCR轻松搞定验证码

    2023-02-20 17:10:54
  • SQL Server中单引号的两种处理技巧

    2008-05-23 13:30:00
  • Python关键字 asynico基本用法

    2023-02-19 08:34:42
  • MySQL查看版本的五种方法总结

    2024-01-16 08:22:04
  • 谈一谈JS消息机制和事件机制的理解

    2024-05-03 15:59:22
  • OpenCV特征提取与检测之Harris角点检测

    2021-06-05 10:45:51
  • Python Flask异步发送邮件实现方法解析

    2023-08-15 04:29:12
  • 浅谈python已知元素,获取元素索引(numpy,pandas)

    2023-08-04 16:01:00
  • 那些看一眼就让你难忘的广告

    2007-09-21 19:46:00
  • ASP连接MSSQL2005 数据库

    2009-03-08 19:20:00
  • Python从数据库读取大量数据批量写入文件的方法

    2024-01-27 14:48:10
  • 如何利用python检测图片是否包含二维码

    2021-04-13 01:42:53
  • 详解css定位与定位应用

    2007-05-11 16:52:00
  • asp之家 网络编程 m.aspxhome.com