600字范文,内容丰富有趣,生活中的好帮手!
600字范文 > gevent和requests同时使用报requests.exceptions.ReadTimeout:HTTPSConnectionPool(host='www.baidu.com' port=4

gevent和requests同时使用报requests.exceptions.ReadTimeout:HTTPSConnectionPool(host='www.baidu.com' port=4

时间:2024-03-11 02:38:05

相关推荐

gevent和requests同时使用报requests.exceptions.ReadTimeout:HTTPSConnectionPool(host='www.baidu.com'  port=4

最近项目需要用协程来处理网站并发访问,使用了Gevent这个库,访问网站用requests,然而访问https的url时报错:

>>> from gevent import monkey; monkey.patch_socket()>>> import gevent>>> url=''>>> requests.get(url)

requests.exceptions.ReadTimeout:HTTPSConnectionPool(host='', port=443): Read timed out. (read timeout=None)

一开始还以为是网络连接的问题,然而使用wget并没有问题。设定requests的timeout参数同样没有作用。改用urllib2库,报的是下面这个异常:

urllib2.URLError: <urlopen error [Errno 2] _ssl.c:504: The operation did not complete (read)>

通过下面这个网站:

/questions/20580252/python-requests-module-throws-exception-with-gevent

得到了解决方法:

>>> from gevent import monkey; monkey.patch_ssl()>>> requests.get(url)<Response [200]>

这次的问题是因为对Gevent库不熟悉,同时只想着粘贴代码完成功能。结果GG了。

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。