def get_parsed_body(request):
"""Get the body (json or formData) of the request parsed.
Args:
request: request object to get the body from.
Returns:
A dictionary of the body.
Raises:
ValueError: if it is neither a json or a formData
"""
data = None
if not request.parsed_body == '':
try:
data = json.loads(request.body.decode('utf-8'))
except Exception: # Decode formData
data = dict(parse_qsl(request.body))
if not data: # Not a form data
raise
return data
评论列表
文章目录