diff options
-rw-r--r-- | AUTHORS.rst | 1 | ||||
-rw-r--r-- | requests/models.py | 23 | ||||
-rw-r--r-- | tests/test_lowlevel.py | 41 |
3 files changed, 3 insertions, 62 deletions
diff --git a/AUTHORS.rst b/AUTHORS.rst index e2772065..5477e58c 100644 --- a/AUTHORS.rst +++ b/AUTHORS.rst @@ -189,4 +189,3 @@ Patches and Suggestions - Antti Kaihola (`@akaihola <https://github.com/akaihola>`_) - "Dull Bananas" <dull.bananas0@gmail.com> (`@dullbananas <https://github.com/dullbananas>`_) - Alessio Izzo (`@aless10 <https://github.com/aless10>`_) -- Belavin Denis (`@luckydenis <https://github.com/luckydenis>`_) diff --git a/requests/models.py b/requests/models.py index a60b5f44..edd16240 100644 --- a/requests/models.py +++ b/requests/models.py @@ -641,10 +641,6 @@ class Response(object): #: is a response. self.request = None - #: If there was an error in the processing of content, - #: then save the error that would return the same error when you re-appeal. - self._error = None - def __enter__(self): return self @@ -754,21 +750,12 @@ class Response(object): try: for chunk in self.raw.stream(chunk_size, decode_content=True): yield chunk - except ProtocolError as e: - self._error = ChunkedEncodingError(e) - + raise ChunkedEncodingError(e) except DecodeError as e: - self._error = ContentDecodingError(e) - + raise ContentDecodingError(e) except ReadTimeoutError as e: - self._error = ConnectionError(e) - - finally: - # if we had an error - throw the saved error - if self._error: - raise self._error - + raise ConnectionError(e) else: # Standard file-like object. while True: @@ -841,10 +828,6 @@ class Response(object): else: self._content = b''.join(self.iter_content(CONTENT_CHUNK_SIZE)) or b'' - # if we had an error - throw the saved error - 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. diff --git a/tests/test_lowlevel.py b/tests/test_lowlevel.py index 4178c78a..4127fb11 100644 --- a/tests/test_lowlevel.py +++ b/tests/test_lowlevel.py @@ -3,7 +3,6 @@ import pytest import threading import requests -from requests.exceptions import ChunkedEncodingError from tests.testserver.server import Server, consume_socket_content @@ -308,43 +307,3 @@ def test_fragment_update_on_redirect(): assert r.url == 'http://{}:{}/final-url/#relevant-section'.format(host, port) close_server.set() - - -def test_response_content_retains_error(): - """Verify that accessing response.content retains an error. - - See https://github.com/kennethreitz/requests/issues/4965 - """ - - data = "Some random stuff to read from remove server.\n" - - def response_handler(sock): - req = consume_socket_content(sock, timeout=0.5) - - # Send invalid chunked data (length mismatch) - sock.send( - b'HTTP/1.1 200 OK\r\n' - b'Transfer-Encoding: chunked\r\n' - b'\r\n2\r\n42\r\n8\r\n123\r\n' # 5 bytes missing - ) - - close_server = threading.Event() - server = Server(response_handler, wait_to_close_event=close_server) - - with server as (host, port): - url = 'http://{}:{}/path'.format(host, port) - r = requests.post(url, stream=True) - with pytest.raises(ChunkedEncodingError): - r.content - - # Access the bad response data again, I would expect the same - # error again. - - try: - content = r.content - except ChunkedEncodingError: - pass # fine, same exception - else: - assert False, "error response has content: {0!r}".format(content) - close_server.set() - |