我试图在Flask中创建一个简单的api,第一步是获取POST-json数据。(我现在只想打印它)这是我的代码,当我用json数据请求/api时,它返回一个500错误。有没有想过为什么会这样?from flask import Flask, request, Response
app = Flask(__name__)
@app.route('/')
def root_response():
return "Hello World."
@app.route('/api', methods=['POST', 'GET'])
def api_response():
if request.method == 'POST':
return request.json
if __name__ == '__main__':
app.run()
curl命令:$ curl -H "Content-Type: application/json" --data @body.json http://127.0.0.1:5000/api
500 Internal Server ErrorInternal Server Error
The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application.
正文.json:{
"please": "print",
"me": "now"
}