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


#1

I’m using the python package requests to send requests to https://mobile.twitter.com/username/following.

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 https://api.twitter.com/1.1/friends/ids.json. 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 https://mobile.twitter.com/username/followers 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’)
#2

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)


#3

the code send requests to https://mobile.twitter.com/username/followers is in here

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


#4

this is the traceback for the third exception:

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