From 00da04b4d41fd679a10db01c6a2b2415d4023328 Mon Sep 17 00:00:00 2001 From: rr- Date: Sun, 10 Apr 2016 15:59:10 +0200 Subject: [PATCH] server/api: fix decoding JSON --- server/szurubooru/middleware/json_translator.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/server/szurubooru/middleware/json_translator.py b/server/szurubooru/middleware/json_translator.py index bb15c35..e59d222 100644 --- a/server/szurubooru/middleware/json_translator.py +++ b/server/szurubooru/middleware/json_translator.py @@ -32,7 +32,7 @@ class JsonTranslator(object): request.context.files[key] = form.getvalue(key) body = form.getvalue('metadata') else: - body = request.stream.read().decode('utf-8') + body = request.stream.read() if not body: raise falcon.HTTPBadRequest( @@ -40,6 +40,9 @@ class JsonTranslator(object): 'A valid JSON document is required.') try: + if isinstance(body, bytes): + body = body.decode('utf-8') + request.context.request = json.loads(body) except (ValueError, UnicodeDecodeError): raise falcon.HTTPError(