记录一个奇葩 bug [Failed to decode JSON object: Expecting value: line 1 column 1 (char 0)]
关于 flask 的一个记录
代码
@auth.login_required
@app.route('/add', methods=['POST'])
def add():
if request.method != 'POST':
return False
print(request.json)
return "hello"
发送请求
curl localhost:5000/add -X POST -d @temp/api.json -H "Content-type: application/json" --digest -u aa:bb
报错
api.json文件格式是正确的
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<title>400 Bad Request</title>
<h1>Bad Request</h1>
<p>Failed to decode JSON object: Expecting value: line 1 column 1 (char 0)</p>
原因
写反了
@auth.login_required
@app.route('/add', methods=['POST'])```
正确的顺序应该是
@app.route('/add', methods=['POST'])
@auth.login_required