【发布时间】:2021-02-23 08:55:31
【问题描述】:
所以我正在测试 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
【问题讨论】:
-
您应该再次检查您的 Postman 设置。 Http 400 表示错误来自客户端请求端。
标签: python-3.x flask postman flask-sqlalchemy