我正在尝试向 API 添加一个 DELETE 方法,如下所示:
if request.method == 'DELETE':
if request.headers['Content-Type'] == 'application/json':
try:
data = json.loads(request.data)
data_id = data['id']
db.execute('DELETE FROM places WHERE id=' + data_id)
db.commit()
resp = Response({"Delete Success!"}, status=200, mimetype='application/json')
return resp
except (ValueError, KeyError, TypeError):
resp = Response({"JSON Format Error."}, status=400, mimetype='application/json')
return resp
我正在传递以下 CURL:
curl -H "Content-type: applicaiton/json" -X DELETE http://localhost:5000/location -d '{"id":3}'
try except 块由于某种原因失败。我无法检测到问题所在。有什么想法可以调试吗?