From 7cc02e84edf7a318b43d0e0a04fd09543c9863df Mon Sep 17 00:00:00 2001 From: messense Date: Mon, 15 May 2017 10:11:25 +0800 Subject: [PATCH] Fix json loads bug on Python 3.5 --- sanic/request.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/sanic/request.py b/sanic/request.py index 57b4773c..e590e75c 100644 --- a/sanic/request.py +++ b/sanic/request.py @@ -1,3 +1,5 @@ +import sys +import json from cgi import parse_header from collections import namedtuple from http.cookies import SimpleCookie @@ -7,7 +9,12 @@ from urllib.parse import parse_qs, urlunparse try: from ujson import loads as json_loads except ImportError: - from json import loads as json_loads + if sys.version_info[:2] == (3, 5): + def json_loads(data): + # on Python 3.5 json.loads only supports str not bytes + return json.loads(data.decode()) + else: + json_loads = json.loads from sanic.exceptions import InvalidUsage from sanic.log import log