简体   繁体   English

PowerShell:无法解码 JSON object:期望属性名称用双引号括起来

[英]PowerShell: Failed to decode JSON object: Expecting property name enclosed in double quotes

I was trying to run my first command with POST method:我试图用 POST 方法运行我的第一个命令:

curl --header "Content-Type: application/json" --request POST --data '{"flower":"1,2,3,7"}' http://localhost:5000/iris_post

But I got an error:但我得到一个错误:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<title>400 Bad Request</title>
<h1>Bad Request</h1>
<p>Failed to decode JSON object: Expecting property name enclosed in double quotes: line 1 column 2 (char 1)</p>

My code for POST method is very simple:我的 POST 方法代码非常简单:

from flask import Flask, request
app = Flask(__name__)
@app.route('/iris_post', methods=['POST'])
def add_message():
    content = request.get_json()
    return str(content)

Where is the problem?问题出在哪里?

UPD :更新

It seems that I have a problem with my PowerShell.看来我的 PowerShell 有问题。 PowerShell doesn't have curl by default but I fixed it with Remove-item alias:curl . PowerShell 默认没有curl但我用Remove-item alias:curl修复了它。 I don't know why but it leads to the error above.我不知道为什么,但这会导致上面的错误。 The same command works fine in Git Bash.相同的命令在 Git Bash 中工作正常。

I've run your code and it worked smoothly here.我已经运行了您的代码,并且在这里运行顺利。 In order to reproduce your error, I've replaced single quote argument by double quote in the POST data:为了重现您的错误,我在 POST 数据中用双引号替换了单引号参数:

POST --data "{"flower":"1,2,3,7"}"

This way the error appeared here also.这样错误也出现在这里。 But using single quote, as you typed, it worked as expected.但是在您键入时使用单引号,它按预期工作。 So it seems a typo error.所以这似乎是一个拼写错误。

Have you try the Invoke-RestMethod?您是否尝试过 Invoke-RestMethod?

$url = 'http://localhost:5000/iris_post'
data = '{"flower":"1,2,3,7"}'
Invoke-RestMethod $url -Method Post -Body $data -ContentType 'application/x-www-form-urlencoded'

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 烧瓶/Keras:<p> 无法解码 JSON object:期望用双引号括起来的属性名称:第 1 行第 2 列(字符 1)</p> - Flask/Keras: <p>Failed to decode JSON object: Expecting property name enclosed in double quotes: line 1 column 2 (char 1)</p> json.decoder.JSONDecodeError:需要用双引号引起来的属性名称 - json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes Python/Json:期望用双引号引起来的属性名称 - Python/Json:Expecting property name enclosed in double quotes 期望用双引号括起来的属性名称 - 使用Python将字符串转换为json对象 - Expecting property name enclosed in double quotes - converting a string to a json object using Python Oandapy:期望属性名称用双引号引起来 - Oandapy: Expecting property name enclosed in double quotes JSONDecodeError:期望用双引号括起来的属性名称 - JSONDecodeError: Expecting property name enclosed in double quotes 期望用双引号括起来的属性名称 - Expecting property name enclosed in double quotes Discord中的“期望属性名称用双引号引起来” - “Expecting property name enclosed in double quotes” in Discord json.decoder.JSONDecodeError:期望值:,json.decoder.JSONDecodeError:期望属性名称用双引号引起来: - json.decoder.JSONDecodeError: Expecting value: , json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes: json.decoder.JSONDecodeError:期望属性名称用双引号引起来:读取 json 时第 2 行第 1 列(char 2)? - json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes: line 2 column 1 (char 2) when reading a json?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM