common_hooks.py 文件源码

python
阅读 16 收藏 0 点赞 0 评论 0

项目:kge-server 作者: vfrico 项目源码 文件源码
def read_body_as_json(req):
    """Reads the request body and returns a dict with the content

    If body is empty, returns a void python dictionary

    :return: A dictionary or similar python object (list)
    :rtype: Object
    """
    try:
        body_req = req.stream.read().decode('utf-8')
        if body_req is None or body_req == "":
            return {}
        else:
            return json.loads(body_req)

    except (json.decoder.JSONDecodeError) as err:
        msg = ("Please, read the documentation carefully and try again. "
               "Couldn't decode the input stream (body).")
        raise falcon.HTTPBadRequest(
            title="Couldn't read body correctly from HTTP request",
            description=str(msg))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号