Flask错误处理:"响应对象不可迭代"

Chr*_*ris 7 python rest curl flask

我正在尝试使用Flask设置REST Web服务.我遇到了错误处理问题@app.errorhandler(404)

#!flask/bin/python
from flask import Flask, jsonify, abort

app = Flask(__name__)

@app.errorhandler(404)
def not_found(error):
    return jsonify({'error':'not found'}), 404

if __name__ == '__main__':
app.run(debug = True)
Run Code Online (Sandbox Code Playgroud)

当我发现它时,我什么都没得到.在我的调试器中,它告诉我我有一个TypeError: 'Response' object is not iterable

jsonify在另一个方法中使用了没有问题的字典,但是当我将其作为错误返回时,它不起作用.有任何想法吗?

fal*_*tru 9

from flask import Flask, jsonify

app = Flask(__name__)

@app.errorhandler(404)
def not_found(error):
    return jsonify({'error':'not found'}), 404

app.run()
Run Code Online (Sandbox Code Playgroud)

使用上面的代码,curl http://localhost:5000/给我:

{
  "error": "not found"
}
Run Code Online (Sandbox Code Playgroud)

你在用flask.jsonify吗?