Python 烧瓶过帐JSON
我有以下方法:Python 烧瓶过帐JSON,python,curl,Python,Curl,我有以下方法: @app.route('/change_groups', methods = ['POST']) def change_groups(): if not request.json: return "Not a json post" return "json post!" 当我像这样卷曲时,我得到了预期的“不是json帖子”: curl --data "param1=value1¶m2=value2" localhost:8000/change_g
@app.route('/change_groups', methods = ['POST'])
def change_groups():
if not request.json:
return "Not a json post"
return "json post!"
当我像这样卷曲时,我得到了预期的“不是json帖子”
:
curl --data "param1=value1¶m2=value2" localhost:8000/change_groups
然后我尝试发布json以触发“json post!”
代码:
curl -X POST -d '{"username":"xyz","password":"xyz"}' http://localhost:8000/change_groups
第二个请求还触发了“非json帖子”
,而我正期待“json帖子!”
如何将发布json类似于此Flask路由?快速找到答案,需要添加标题数据:
-H "Content-Type: application/json"
在您的请求中,您没有设置
内容类型:application/json
,因此它不会被解析为json