25

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.

I've tried monkey patching the ssl module(gevent.monkey.patch_all()) and some others too but no luck.

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

I'm using latest 1.0rc Gevent version.

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

tshepang
  • 12,111
  • 21
  • 91
  • 136
user962563
  • 495
  • 1
  • 4
  • 14
  • 1
    have you tried [forcing TLSv1 as suggested here](http://stackoverflow.com/questions/14102416/python-requests-requests-exceptions-sslerror-errno-8-ssl-c504-eof-occurred)? – jfs May 25 '13 at 11:57
  • I will try this fix also. My only concern is that when running the task with Gevent Pool size=1 I don't get any errors at all, but when I try to run more (2 to 10) errors get more common (network unreachable, EOF ssl error, no such file or directory). So to me it seems its gevent issue? – user962563 May 25 '13 at 13:14
  • I don't know the current status of `gevent` / `requests` compatibility. Have you tried `grequests`? – jfs May 25 '13 at 14:56
  • The TLSv1 force fix seems to do the trick, there is no more SSL errors. However...with this fix enabled I keep getting error OperationalError: unable to open database file (using sqllite3) after about 7k writes to database. Which is odd since this error is supposed to happen right from the start if celery didn't have access to db and not after 7k successful transactions... – user962563 May 25 '13 at 17:41
  • Weird I get this error using my phone's wifi/tethering and FTPS, but NOT while the same code and standard wifi. – pyCthon May 08 '15 at 22:23

3 Answers3

13

Using the forced TLSv1 fix as suggested by J.F Sebastian fixed all the issues I was facing.

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

Community
  • 1
  • 1
user962563
  • 495
  • 1
  • 4
  • 14
1

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).

some user
  • 876
  • 1
  • 12
  • 26
0

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 install ndg-httpsclient
pip install pyopenssl
pip install pyasn1

It removed my SSLError: EOF occurred in violation of protocol (_ssl.c:590) error.

Hope it helps.

Ashwin Dhakal
  • 31
  • 1
  • 5