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 <https://github.com/kennethreitz/requests/issues/377>

This commit is contained in:
Michael Newman
2012-04-08 18:39:44 -04:00
parent c7b1bc8197
commit b92feb3f0a
2 changed files with 8 additions and 3 deletions
+3 -3
View File
@@ -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):
+5
View File
@@ -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()