Requests: SSLError: EOF 发生违反协议 (_ssl.c:590)

创建于 2016-07-09  ·  6评论  ·  资料来源: psf/requests

请耐心等待,因为我对 Python 和 github 总体上还是很陌生。

我一直在使用请求从 Play 商店抓取数据。 我需要发出大量请求(大约 20k)。 它适用于大约 3000-4000 个请求,但之后卡住了(SSL 错误)。 我不熟悉 SSL 和请求,所以我不知道是什么原因造成的。

错误:

(SSLError                                  Traceback (most recent call last)
<ipython-input-23-1da544640d89> in <module>()
     53         time.sleep(0.1)
     54 
---> 55         r = requests.get('https://play.google.com' + link + '&hl=en')
     56         link_tree = html.fromstring(r.content)
     57         description = link_tree.xpath('//div[@jsname="C4s9Ed"]/text()') + link_tree.xpath('//div[@jsname="C4s9Ed"]/p/text()')

C:\Users\Nathan\AppData\Local\Enthought\Canopy\User\lib\site-packages\requests\api.pyc in get(url, params, **kwargs)
     65 
     66     kwargs.setdefault('allow_redirects', True)
---> 67     return request('get', url, params=params, **kwargs)
     68 
     69 

C:\Users\Nathan\AppData\Local\Enthought\Canopy\User\lib\site-packages\requests\api.pyc in request(method, url, **kwargs)
     51     # cases, and look like a memory leak in others.
     52     with sessions.Session() as session:
---> 53         return session.request(method=method, url=url, **kwargs)
     54 
     55 

C:\Users\Nathan\AppData\Local\Enthought\Canopy\User\lib\site-packages\requests\sessions.pyc in request(self, method, url, params, data, headers, cookies, files, auth, timeout, allow_redirects, proxies, hooks, stream, verify, cert, json)
    466         }
    467         send_kwargs.update(settings)
--> 468         resp = self.send(prep, **send_kwargs)
    469 
    470         return resp

C:\Users\Nathan\AppData\Local\Enthought\Canopy\User\lib\site-packages\requests\sessions.pyc in send(self, request, **kwargs)
    574 
    575         # Send the request
--> 576         r = adapter.send(request, **kwargs)
    577 
    578         # Total elapsed time of the request (approximately)

C:\Users\Nathan\AppData\Local\Enthought\Canopy\User\lib\site-packages\requests\adapters.pyc in send(self, request, stream, timeout, verify, cert, proxies)
    445         except (_SSLError, _HTTPError) as e:
    446             if isinstance(e, _SSLError):
--> 447                 raise SSLError(e, request=request)
    448             elif isinstance(e, ReadTimeoutError):
    449                 raise ReadTimeout(e, request=request)

SSLError: EOF occurred in violation of protocol (_ssl.c:590) )

这个github上的-efi在这个线程上似乎有同样的问题: https :

我已经坚持了很长一段时间,我在这里也找不到任何答案,也找不到 StackOverflow(答案可能就在我的眼皮子底下,但由于我缺乏 SSL 和请求方面的知识,我很难理解它们) .

在此先感谢您的帮助,如果有不清楚的地方,我们很抱歉——请告诉我。

最有用的评论

我有完全相同的错误消息,问题是我没有安装 ndg-httpsclient

https://github.com/kennethreitz/requests/issues/3605

所有6条评论

当你说你被卡住时,是不是只是触发了异常? 或者后续请求不起作用? 我问是因为瞬态网络错误 _do_ 发生,如果您发出大量 Web 请求,您应该考虑在面对它们时实现某种重试逻辑。

异常触发。 后续请求似乎有效,但我还没有尝试实现重试。 我担心我违反了向服务器或其他东西发出过多请求的规则,我猜。

我一定会尝试并更新此线程。 谢谢!

好吧,它的价值在于,因为您使用的是requests.*您将自己置于更大的风险中,使您与服务器之间的网络资源过载。 您应该尝试使用session

对于任何有此问题的人:

我已经按照@Lukasa的建议修复了它,并在导入请求后添加了这个:

import requests
sess = requests.Session()
adapter = requests.adapters.HTTPAdapter(max_retries = 20)
sess.mount('http://', adapter)

然后,在我之前使用requests.get() ,我使用了sess.get()

希望这会有所帮助,并感谢您的帮助@Lukasa

我有完全相同的错误消息,问题是我没有安装 ndg-httpsclient

https://github.com/kennethreitz/requests/issues/3605

@variable我安装了 ndg-httpsclient 但同样的错误:urllib.error.URLError

此页面是否有帮助?
0 / 5 - 0 等级

相关问题

8key picture 8key  ·  3评论

justlurking picture justlurking  ·  3评论

thadeusb picture thadeusb  ·  3评论

eromoe picture eromoe  ·  3评论

JimHokanson picture JimHokanson  ·  3评论