mirror of
https://github.com/kennethreitz/requests.git
synced 2026-06-05 14:50:16 +00:00
#4965 fix-draw: Accessing response.content twice removes forgets read error.
This commit is contained in:
@@ -189,3 +189,4 @@ Patches and Suggestions
|
||||
- Darren Dormer (`@ddormer <https://github.com/ddormer>`_)
|
||||
- Rajiv Mayani (`@mayani <https://github.com/mayani>`_)
|
||||
- Antti Kaihola (`@akaihola <https://github.com/akaihola>`_)
|
||||
- Belavin Denis (`@luckydenis <https://github.com/luckydenis>`_)
|
||||
|
||||
@@ -640,6 +640,8 @@ class Response(object):
|
||||
#: is a response.
|
||||
self.request = None
|
||||
|
||||
self.error = None
|
||||
|
||||
def __enter__(self):
|
||||
return self
|
||||
|
||||
@@ -750,10 +752,13 @@ class Response(object):
|
||||
for chunk in self.raw.stream(chunk_size, decode_content=True):
|
||||
yield chunk
|
||||
except ProtocolError as e:
|
||||
self._error = e
|
||||
raise ChunkedEncodingError(e)
|
||||
except DecodeError as e:
|
||||
self._error = e
|
||||
raise ContentDecodingError(e)
|
||||
except ReadTimeoutError as e:
|
||||
self._error = e
|
||||
raise ConnectionError(e)
|
||||
else:
|
||||
# Standard file-like object.
|
||||
@@ -827,6 +832,9 @@ class Response(object):
|
||||
else:
|
||||
self._content = b''.join(self.iter_content(CONTENT_CHUNK_SIZE)) or b''
|
||||
|
||||
if self._error is not None:
|
||||
raise self._error
|
||||
|
||||
self._content_consumed = True
|
||||
# don't need to release the connection; that's been handled by urllib3
|
||||
# since we exhausted the data.
|
||||
|
||||
Reference in New Issue
Block a user