]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
httpclient: HTTPResponse.body returns empty string instead of raising 2629/head
authorBen Darnell <ben@bendarnell.com>
Sat, 23 Mar 2019 15:11:18 +0000 (11:11 -0400)
committerBen Darnell <ben@bendarnell.com>
Sat, 23 Mar 2019 15:11:18 +0000 (11:11 -0400)
In tornado 5, HTTPResponse.body would return None if there was no body
buffer (which included errors like timeouts and socket errors, but not
HTTP errors like 404). In tornado 6 this was changed to never return
None (to make it easier to work with type annotations) and raise an
error instead. This turned out to be disruptive, so change it back to
returning a value without raising (but now it's an empty byte string
instead of None).

Fixes #2626

tornado/httpclient.py

index 33abe2e16e943df6bdb2a9d4b15c96e335ac2824..882600af82dbed2c9d695da3dacea994368f8f99 100644 (file)
@@ -665,7 +665,7 @@ class HTTPResponse(object):
     @property
     def body(self) -> bytes:
         if self.buffer is None:
-            raise ValueError("body not set")
+            return b""
         elif self._body is None:
             self._body = self.buffer.getvalue()