From 62f3cddec4d6d01b3bd94f9b5ebfbc0c030d3619 Mon Sep 17 00:00:00 2001 From: Ben Darnell Date: Sat, 23 Mar 2019 11:11:18 -0400 Subject: [PATCH] httpclient: HTTPResponse.body returns empty string instead of raising 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 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tornado/httpclient.py b/tornado/httpclient.py index 33abe2e16..882600af8 100644 --- a/tornado/httpclient.py +++ b/tornado/httpclient.py @@ -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() -- 2.47.2