Flask RESTful POST JSON失败 [英] Flask RESTful POST JSON fails
本文介绍了Flask RESTful POST JSON失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个问题发布JSON通过curl从cmd(Windows7)到Flask RESTful。
这是我发布的:
I have a problem posting JSON via curl from cmd (Windows7) to Flask RESTful. This is what I post:
curl.exe -i -H "Content-Type: application/json" \
-H "Accept: application/json" -X POST \
-d '{"Hello":"Karl"}' http://example.net:5000/
这会导致一个错误的请求,我也不知道如何调试这个,通常我打印出信息到控制台,但这不工作。如何调试wsgi应用程序?看起来像一个绝望的任务...
It results in a bad request, also I don't know how to debug this, normally I would print out information to console, but this doesn't work. How do you debug wsgi apps? Seems like a hopeless task...
这是我在网上看到的简单的测试应用程序:
This is my simple test app as seen on the net:
from flask import Flask, request
from flask.ext.restful import Resource, Api
app = Flask(__name__)
api = Api(app)
class Test(Resource):
def post(self):
#printing request.data works
json_data = request.get_json(force=True) # this issues Bad request
# request.json also does not work
return {}
api.add_resource(Test, '/')
if __name__ == '__main__':
app.run(debug=True)
推荐答案
-d'{Hello:Karl}'
-d "{\"Hello\":\"Karl\"}"
这篇关于Flask RESTful POST JSON失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文