python requests session failed to read the response

python requests session failed to read the response after reading a large response content
python version 2.7
requests 2.3.0

I am using requests.Session in a REST client to talk to REST Server. Some of my endpoints are reading file content and producing file contents as response content. So whenever the response content is more than certain size like 10240 bytes then the subsequent request in the same session is failing(First request succeeds(which response is more than 10240 bytes) and second request keeps on waiting to read the response). 

```
sess = requests.Session()
sess.verify = False
host = "https://somehost/endpoint/"
res = sess.get(url = host+'obj1/28/content', headers = headers)
print res  # this result received successfully with 200 response status code

url = host + 'obj2/1/content'
res = sess.get(url = url, headers=headers)  # the execution struck here. I need to kill the process to exit.
print "content ", res.content     # this line never gets executed...
```

But the same set of requests works fine with out 'requests.Session' using 'requests.get'. Looks like an issue in the urllib3/requests module but I am not sure.

The below are the stack trace when I exited the client manually.

```
File "/opt/lib/python2.7/site-packages/requests/sessions.py", line 556, in send
    r = adapter.send(request, **kwargs)
  File "/opt/lib/python2.7/site-packages/requests/adapters.py", line 391, in send
    r.content
  File "/opt/lib/python2.7/site-packages/requests/models.py", line 690, in content
    self._content = bytes().join(self.iter_content(CONTENT_CHUNK_SIZE)) or bytes()
  File "/opt/lib/python2.7/site-packages/requests/models.py", line 628, in generate
    for chunk in self.raw.stream(chunk_size, decode_content=True):
  File "/opt/lib/python2.7/site-packages/requests/packages/urllib3/response.py", line 240, in stream
    data = self.read(amt=amt, decode_content=decode_content)
  File "/opt/lib/python2.7/site-packages/requests/packages/urllib3/response.py", line 187, in read
    data = self._fp.read(amt)
  File "/opt/lib/python2.7/httplib.py", line 567, in read
    s = self.fp.read(amt)
  File "/opt/lib/python2.7/httplib.py", line 1313, in read
    return s + self._file.read(amt - len(s))
  File "/opt/lib/python2.7/socket.py", line 380, in read
    data = self._sock.recv(left)
  File "/opt/lib/python2.7/ssl.py", line 242, in recv
    return self.read(buflen)
  File "/opt/lib/python2.7/ssl.py", line 161, in read
    return self._sslobj.read(len)
```


Thanks for this!

You've cut out the actual exception raised, you're only showing the traceback. What exact exception is being thrown?


Closing for inactivity.


Hi,

Give me some more time. I will reproduce this and will provide with more information.


@msrajan when you do, we'll reopen the issue if it's truly a bug in requests.


Is it connected to this stack overflow question http://stackoverflow.com/questions/25255900/python-requests-session-failed-to-read-the-response-after-reading-a-big-more-th


@mobcdi this issue was opened after @msrajan was told to open it on StackOverflow. That said, no one has been able to reproduce this or provide sufficient information for us to debug it. Further, please do not revive old issues unless you have something to add in the way of information.


Hi,

I am able to reproduce this issue. Please let me know what information do I need to provide for further investigation. Stacktrace is same as given by msrajan.

```
  File "/localdisk/myProject/env/lib/python2.7/site-packages/requests/sessions.py", line 487, in get
    return self.request('GET', url, **kwargs)
  File "/localdisk/myProject/env/lib/python2.7/site-packages/requests/sessions.py", line 475, in request
    resp = self.send(prep, **send_kwargs)
  File "/localdisk/myProject/env/lib/python2.7/site-packages/requests/sessions.py", line 585, in send
    r = adapter.send(request, **kwargs)
  File "/localdisk/myProject/env/lib/python2.7/site-packages/requests/adapters.py", line 403, in send
    timeout=timeout
  File "/localdisk/myProject/env/lib/python2.7/site-packages/requests/packages/urllib3/connectionpool.py", line 578, in urlopen
    chunked=chunked)
  File "/localdisk/myProject/env/lib/python2.7/site-packages/requests/packages/urllib3/connectionpool.py", line 385, in _make_request
    httplib_response = conn.getresponse(buffering=True)
  File "/usr/lib64/python2.7/httplib.py", line 1045, in getresponse
    response.begin()
  File "/usr/lib64/python2.7/httplib.py", line 409, in begin
    version, status, reason = self._read_status()
  File "/usr/lib64/python2.7/httplib.py", line 365, in _read_status
    line = self.fp.readline(_MAXLINE + 1)
  File "/usr/lib64/python2.7/socket.py", line 476, in readline
    data = self._sock.recv(self._rbufsize)
  File "/usr/lib64/python2.7/ssl.py", line 241, in recv
    return self.read(buflen)
  File "/usr/lib64/python2.7/ssl.py", line 160, in read
    return self._sslobj.read(len)
KeyboardInterrupt
```


Do you have sample code we can run to verify the problem?


Well the code is IP so I can not possibly share here, sorry for that.

But the steps are exactly same as mentioned by msrajan above.


@kagupta28 Are you talking to a proprietary server, or one that I can reach on the open web?

This issue is almost certainly caused by the combination of the request that we emit and the response we receive, and if I can't reproduce or see those it is very difficult for me to assist you.


@Lukasa understand that... talking to a proprietary server. Just thinking what can be done to help investigate this issue further.


If you're able to, you can pass me a wireshark trace to my personal email address that I'll keep private. Otherwise, there is very little we can do to assist you.