问题描述
我正在使用Django Celery任务通过Gevent使用请求库连接到Facebook Graph API。我经常遇到的问题是,我偶尔会发生EOF违反协议异常的情况。我到处搜索,各种来源提供了不同的修复程序,但似乎都没有用。
I'm using Django Celery task to connect to Facebook Graph API with requests lib using Gevent. Issue I'm constantly running at is that every now and then I get EOF occurred in violation of protocol exception. I've searched around and various sources offer different fixes but none seems to work.
我尝试用猴子修补ssl模块(gevent.monkey.patch_all())和其他一些修补程序,但是没有运气。
I've tried monkey patching the ssl module(gevent.monkey.patch_all()) and some others too but no luck.
我什至不确定这是否是openssl问题,因为一些消息来源可能会建议,因为在应用Gevent优化之前我还没有遇到过
I'm not even sure if this is openssl issue as some sources might suggest as I haven't encountered it before applying Gevent optimisation
Connection error: [Errno 8] _ssl.c:504: EOF occurred in violation of protocol
Traceback (most recent call last):
File "/home/user/workspace/startup/project/events/tasks.py", line 52, in _process_page
data = requests.get(current_url)
File "/home/user/workspace/startup/env/local/lib/python2.7/site-packages/requests/api.py", line 55, in get
return request('get', url, **kwargs)
File "/home/user/workspace/startup/env/local/lib/python2.7/site-packages/requests/api.py", line 44, in request
return session.request(method=method, url=url, **kwargs)
File "/home/user/workspace/startup/env/local/lib/python2.7/site-packages/requests/sessions.py", line 354, in request
resp = self.send(prep, **send_kwargs)
File "/home/user/workspace/startup/env/local/lib/python2.7/site-packages/requests/sessions.py", line 460, in send
r = adapter.send(request, **kwargs)
File "/home/user/workspace/startup/env/local/lib/python2.7/site-packages/requests/adapters.py", line 250, in send
raise SSLError(e)
SSLError: [Errno 8] _ssl.c:504: EOF occurred in violation of protocol
我正在使用最新的1.0rc Gevent版本。
I'm using latest 1.0rc Gevent version.
尽管URL正确,但仍会不时弹出的另一个问题是:
连接由于错误(2,'没有这样的文件或目录')'而中断后重试(剩余5次尝试):/ ID / events?limit = 5000& fields = description,名称,位置,开始时间,结束时间& access_token = 令牌
Another issue that keeps poping up time to time although URL is correct is:Retrying (5 attempts remain) after connection broken by 'error(2, 'No such file or directory')': /ID/events?limit=5000&fields=description,name,location,start_time,end_time&access_token=TOKEN
推荐答案
使用强制修复了我面临的所有问题。
Using the forced TLSv1 fix as suggested by J.F Sebastian fixed all the issues I was facing.
有关以下问题的提示:
-
DNSError异常-将Gevent从0.13.X升级到1.0rc可解决此问题
DNSError exception - upgrading Gevent from 0.13.X to 1.0rc fixes this issue
SSL问题-查看JF Sebastian提供的链接中的修复
SSL issues - look at fix in link provided by J.F Sebastian
这篇关于Python SSL连接“发生违反协议的EOF”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!