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

this is the traceback for the second exception:

    Traceback (most recent call last):
      File "gen_friendship.py", line 218, in <module>
        start(sed_login, max_depth)
      File "gen_friendship.py", line 201, in start
        get_followers(node)
      File "gen_friendship.py", line 131, in get_followers
        response = retrieve(FOLLOWERS_URL % name)
      File "gen_friendship.py", line 33, in retrieve
        response = requester.get(url)
      File "/usr/local/lib/python2.7/dist-packages/requests/sessions.py", line 476, in get
        return self.request('GET', url, **kwargs)
      File "/usr/local/lib/python2.7/dist-packages/requests/sessions.py", line 464, in request
        resp = self.send(prep, **send_kwargs)
      File "/usr/local/lib/python2.7/dist-packages/requests/sessions.py", line 576, in send
        r = adapter.send(request, **kwargs)
      File "/usr/local/lib/python2.7/dist-packages/requests/adapters.py", line 431, in send
        raise SSLError(e, request=request)
    requests.exceptions.SSLError: [Errno bad handshake] (-1, 'Unexpected EOF')

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')
Community
  • 1
  • 1
stamaimer
  • 6,227
  • 5
  • 34
  • 55
  • about the second exception, i have figure out what lead to it. because i use lxml to parse the response. and the xpath return value of lxml is [`smart strings`](http://lxml.de/xpathxslt.html#xpath-return-values). so it will lead to memory leak. I follow this [solution](http://stackoverflow.com/questions/5260261/lxml-parser-eats-all-memory) add `smart_strings=False` to solve it. I'll still focus on the third exception. – stamaimer Apr 11 '15 at 15:09

0 Answers0