request.get_json() 返回 400 错误请求

时间:2021-02-23 08:55:31

标签: python-3.x flask postman flask-sqlalchemy

所以我正在测试 POST 以在邮递员中向我的数据库添加新内容,并且它不断返回 400 错误,没有其他信息

127.0.0.1 - - [23/Feb/2021 00:46:04] "[1m[31mPOST /drinks HTTP/1.1[0m" 400 -

我尝试使用 request.is_json 并且它返回 True。代码只要运行到

就返回错误

new_drink = request.get_json()

我不知道我在哪里搞砸了。

@app.route('/drinks',methods=['POST'])
@requires_auth('post:drinks')
def add_drinks(payload):
    new_drink = request.get_json()
    title = new_drink.get('title')
    recipe = new_drink.get('recipe')
    drink = Drink(title=title,recipe=json.dumps(recipe))
    drink.insert()
    result = {
        "success": True,
        "drinks": drink.long()
    }
    return jsonify(result), 200

这是我项目的链接

https://github.com/TYL1026/coffee_shop/blob/main/backend/src/api.py

enter image description here

0 个答案:

没有答案