OpenSSL.SSL.SysCallError: (104, 'Connection reset by peer')


I’m using the python package requests to send requests to

At first, I encounter the exception : requests.exceptions.SSLError: [Errno 8] _ssl.c:504: EOF occurred in violation of protocol. To solve that, I follow this solution to write a SSLAdapter to specify PROTOCOL_TLSv1.

After that, I encounter another exception : requests.exceptions.SSLError: [Errno bad handshake] (-1, 'Unexpected EOF’). And, I found this, but i send request and receive data in the same process.

And then, I use requests to send requests to The second exception is gone(still didn’t understand why). But I encounter third exception : OpenSSL.SSL.SysCallError: (104, ‘Connection reset by peer’). I found this in SO. And I add time.sleep(10) before send requests. But the third exception still happen.

So the second and the third exception still happen. Maybe the response content is too big too read? Or it’s the problem of twitter server(some SO solutions said about it ).

the code send requests to is in here

and the code send requests to twitter rest api followers/ids is in here

Send requests to twitter with `requests` : requests.exceptions.SSLError: [Errno bad handshake] (-1, 'Unexpected EOF’)

Can you show us some actual source code how you are doing the request? Never had issues like that.
(Don’t forget to indent each code line with 4 spaces so it displays properly or Github Backticks syntax)


the code send requests to is in here

and the code send requests to twitter rest api followers/ids is in here


this is the traceback for the third exception:

    Traceback (most recent call last):
      File "", line 283, in <module>
        start(sed_login, max_depth)
      File "", line 266, in start
      File "", line 150, in get_followers
        response = retrieve(FOLLOWERS_URL, params)
      File "", line 72, in retrieve
        response = requester.get(url, params = params, headers = headers)
      File "/usr/lib/python2.6/site-packages/requests/", line 476, in get
        return self.request('GET', url, **kwargs)
      File "/usr/lib/python2.6/site-packages/requests/", line 464, in request
        resp = self.send(prep, **send_kwargs)
      File "/usr/lib/python2.6/site-packages/requests/", line 576, in send
        r = adapter.send(request, **kwargs)
      File "/usr/lib/python2.6/site-packages/requests/", line 370, in send
      File "/usr/lib/python2.6/site-packages/requests/packages/urllib3/", line 544, in urlopen
body=body, headers=headers)
      File "/usr/lib/python2.6/site-packages/requests/packages/urllib3/", line 374, in _make_request
        httplib_response = conn.getresponse()
      File "/usr/lib64/python2.6/", line 990, in getresponse
      File "/usr/lib64/python2.6/", line 391, in begin
version, status, reason = self._read_status()
      File "/usr/lib64/python2.6/", line 349, in _read_status
        line = self.fp.readline()
      File "/usr/lib64/python2.6/", line 433, in readline
        data = recv(1)
      File "/usr/lib/python2.6/site-packages/requests/packages/urllib3/contrib/", line 188, in recv
        data = self.connection.recv(*args, **kwargs)
    OpenSSL.SSL.SysCallError: (104, 'Connection reset by peer')