From 5f140048f4d94a6d7085749f033ced8b7b018dc9 Mon Sep 17 00:00:00 2001 From: Jakob Bowyer Date: Thu, 2 Mar 2017 15:16:01 +0000 Subject: [PATCH] Switched to try/except --- sanic/request.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/sanic/request.py b/sanic/request.py index 95daaa21..954568b4 100644 --- a/sanic/request.py +++ b/sanic/request.py @@ -10,8 +10,10 @@ except ImportError: from json import loads as _json_loads def json_loads(i): - i = i.decode() if isinstance(i, bytes) else i - return _json_loads(i) + try: + return _json_loads(i.decode()) + except AttributeError: + return _json_loads(i) from sanic.exceptions import InvalidUsage from sanic.log import log