From e442a6dcdc52002481fa421a9c7768eada75dc03 Mon Sep 17 00:00:00 2001 From: Michael Atambo Date: Fri, 24 Jan 2014 14:04:00 +0300 Subject: [PATCH] This is a fix to check the argument to RequestHandler.write() is one of the accepted types: dict, bytes or unicode and raise a TypeError otherwise --- tornado/web.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tornado/web.py b/tornado/web.py index b22b11fe6..d3f260bdb 100644 --- a/tornado/web.py +++ b/tornado/web.py @@ -604,6 +604,8 @@ class RequestHandler(object): raise RuntimeError("Cannot write() after finish(). May be caused " "by using async operations without the " "@asynchronous decorator.") + if not isinstance(chunk, (bytes_type, unicode_type, dict)): + raise TypeError("write() only accepts bytes, unicode, and dict objects") if isinstance(chunk, dict): chunk = escape.json_encode(chunk) self.set_header("Content-Type", "application/json; charset=UTF-8") -- 2.47.2