mirror of
https://github.com/kennethreitz/requests.git
synced 2026-06-05 22:50:18 +00:00
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:
+3
-3
@@ -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):
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user