From b92feb3f0af4c4b13e2f65a7601baccb378fd800 Mon Sep 17 00:00:00 2001 From: Michael Newman Date: Sun, 8 Apr 2012 18:39:44 -0400 Subject: [PATCH] If there is no content in a response don't throw an error the second time that content is attempted to be read. This addresses issue #377 --- requests/models.py | 6 +++--- tests/test_requests.py | 5 +++++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/requests/models.py b/requests/models.py index 70e3503..97c97d0 100644 --- a/requests/models.py +++ b/requests/models.py @@ -623,7 +623,7 @@ class Response(object): def __init__(self): - self._content = None + self._content = False self._content_consumed = False #: Integer Code of responded HTTP Status. @@ -736,7 +736,7 @@ class Response(object): def content(self): """Content of the response, in bytes.""" - if self._content is None: + if self._content is False: # Read the contents. try: if self._content_consumed: @@ -751,7 +751,7 @@ class Response(object): except AttributeError: self._content = None - self._content_consumed = True + self._content_consumed = True return self._content def _detected_encoding(self): diff --git a/tests/test_requests.py b/tests/test_requests.py index dd59da2..ac271d1 100755 --- a/tests/test_requests.py +++ b/tests/test_requests.py @@ -800,5 +800,10 @@ class RequestsTestSuite(TestSetup, unittest.TestCase): r = requests.get(httpbin('status', '404')) r.text + def test_no_conent(self): + r = requests.get(httpbin('status', "0"), config={"safe_mode":True}) + r.content + r.content + if __name__ == '__main__': unittest.main() -- 2.34.1