Python SSL连接“违反协议发生EOF”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16748994/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Python SSL connection "EOF occurred in violation of protocol"
提问by user962563
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.
我正在使用 Django Celery 任务通过 Gevent 请求库连接到 Facebook Graph API。我经常遇到的问题是,我时不时地发生违反协议异常的 EOF。我四处搜索,各种来源提供了不同的修复方法,但似乎都不起作用。
I've tried monkey patching the ssl module(gevent.monkey.patch_all()) and some others too but no luck.
我试过猴子修补 ssl 模块(gevent.monkey.patch_all()) 和其他一些,但没有运气。
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
我什至不确定这是否是 openssl 问题,因为某些来源可能会建议,因为我在应用 Gevent 优化之前没有遇到过
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
I'm using latest 1.0rc Gevent version.
我正在使用最新的 1.0rc Gevent 版本。
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
尽管 URL 正确,但仍不时出现的另一个问题是:在连接因“错误(2,“没有这样的文件或目录”)而中断后重试(剩余 5 次尝试):/ ID/events?limit=5000&fields=description ,name,location,start_time,end_time&access_token= TOKEN
采纳答案by user962563
Using the forced TLSv1 fixas suggested by J.F Sebastian fixed all the issues I was facing.
使用JF Sebastian 建议的强制TLSv1 修复解决了我面临的所有问题。
Hints for future questions regarding:
关于未来问题的提示:
DNSError exception - upgrading Gevent from 0.13.X to 1.0rc fixes this issue
SSL issues - look at fix in link provided by J.F Sebastian
DNSError 异常 - 将 Gevent 从 0.13.X 升级到 1.0rc 修复了这个问题
SSL 问题 - 查看 JF Sebastian 提供的链接中的修复
回答by some user
I installed the latest Python 2.7 (2.7.11) and the problem went away. I believe the problem might even be solved back in 2.7.6 (I was using 2.7.5 on Mac OSX).
我安装了最新的 Python 2.7 (2.7.11),问题就解决了。我相信这个问题甚至可以在 2.7.6 中解决(我在 Mac OSX 上使用 2.7.5)。
回答by Ashwin Dhakal
I was having the same error during fetching tweets for my machine learning . Doing the pip install of the following helped me. This works:
我在为我的机器学习获取推文时遇到了同样的错误。执行以下 pip 安装对我有帮助。这有效:
pip install ndg-httpsclient
pip install pyopenssl
pip install pyasn1
It removed my SSLError: EOF occurred in violation of protocol (_ssl.c:590) error.
它删除了我的 SSLError: EOF 发生违反协议 (_ssl.c:590) 错误。
Hope it helps.
希望能帮助到你。

