def process_request(self, req, resp):
req.context['body'] = ''
if req.content_length in (None, 0):
return
body = req.stream.read()
if not body:
raise falcon.HTTPBadRequest('Empty request body', 'A valid JSON document is required.')
try:
req.context['body'] = body.decode('utf-8')
req.context['doc'] = json.loads(req.context['body'])
except (ValueError, UnicodeDecodeError):
raise falcon.HTTPError(
falcon.HTTP_753,
'Malformed JSON', 'Could not decode the request body. The JSON was incorrect or not encoded as UTF-8.',
)
评论列表
文章目录