diff --git a/requests/models.py b/requests/models.py index cce629bb..4e2dd78b 100644 --- a/requests/models.py +++ b/requests/models.py @@ -769,7 +769,7 @@ class Response(object): raise RuntimeError( 'The content for this response was already consumed') - if not self.status_code: + if self.status_code == 0 or self.raw is None: self._content = None else: self._content = bytes().join(self.iter_content(CONTENT_CHUNK_SIZE)) or bytes() diff --git a/tests/test_requests.py b/tests/test_requests.py index a0c47eea..b6667b51 100755 --- a/tests/test_requests.py +++ b/tests/test_requests.py @@ -1094,6 +1094,10 @@ class TestRequests: total_seconds = ((td.microseconds + (td.seconds + td.days * 24 * 3600) * 10**6) / 10**6) assert total_seconds > 0.0 + def test_empty_response_has_content_none(self): + r = requests.Response() + assert r.content is None + def test_response_is_iterable(self): r = requests.Response() io = StringIO.StringIO('abc')