server/api: fix decoding JSON
This commit is contained in:
parent
4faf42ee19
commit
00da04b4d4
|
@ -32,7 +32,7 @@ class JsonTranslator(object):
|
||||||
request.context.files[key] = form.getvalue(key)
|
request.context.files[key] = form.getvalue(key)
|
||||||
body = form.getvalue('metadata')
|
body = form.getvalue('metadata')
|
||||||
else:
|
else:
|
||||||
body = request.stream.read().decode('utf-8')
|
body = request.stream.read()
|
||||||
|
|
||||||
if not body:
|
if not body:
|
||||||
raise falcon.HTTPBadRequest(
|
raise falcon.HTTPBadRequest(
|
||||||
|
@ -40,6 +40,9 @@ class JsonTranslator(object):
|
||||||
'A valid JSON document is required.')
|
'A valid JSON document is required.')
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
if isinstance(body, bytes):
|
||||||
|
body = body.decode('utf-8')
|
||||||
|
|
||||||
request.context.request = json.loads(body)
|
request.context.request = json.loads(body)
|
||||||
except (ValueError, UnicodeDecodeError):
|
except (ValueError, UnicodeDecodeError):
|
||||||
raise falcon.HTTPError(
|
raise falcon.HTTPError(
|
||||||
|
|
Loading…
Reference in New Issue