Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/282.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 烧瓶过帐JSON_Python_Curl - Fatal编程技术网

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&param2=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&param2=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