r.content is None of there's an invalid response.

Fixes #236
This commit is contained in:
Kenneth Reitz
2011-11-04 23:24:38 -04:00
parent 4cae63a297
commit f7968b6797
2 changed files with 10 additions and 1 deletions
+5 -1
View File
@@ -496,7 +496,11 @@ class Response(object):
'already consumed')
# Read the contents.
self._content = self.raw.read()
try:
self._content = self.raw.read()
except AttributeError:
return None
# Decode GZip'd content.
if 'gzip' in self.headers.get('content-encoding', ''):
+5
View File
@@ -529,6 +529,11 @@ class RequestsTestSuite(unittest.TestCase):
assert params3['b'] in r3.content
assert params3['c'] in r3.content
def test_invalid_content(self):
r = requests.get('http://somedomainthatclearlydoesntexistg.com')
assert r.content == None
if __name__ == '__main__':
unittest.main()