我试图使用REST来发送在POST方法的JSON发送JSON,但我得到的错误:脚本使用POST/REST和蟒蛇请求不起作用
"Could not parse JSON data: Expecting value: line 1 column 1
(char 0)", "status": 500, "type": "ValueError",
"request": {"client_addr": "127.0.0.1",
"user_agent": "python-requests/2.3.0 CPython/3.4.2 Linux/3.16.0-41-generic",
"method": "POST", "path": "/api/adley/doc"}}
)
我想修复,使用json.dumps或json.loads,但似乎没有任何工作。
我需要发送一个键和两个值。这是基础:
{
metadata: {
idx_exp: false,
idx_exp_time: 0,
file_ext: false,
password: "",
description: "base de teste",
idx_exp_url: "",
model: {
item: "Text"
},
dt_base: "29/06/2015 14:47:10",
name: "adley",
id_base: 5,
file_ext_time: 0,
},
content: [
{
field: {
required: false,
multivalued: false,
alias: "Texto",
datatype: "Text",
name: "item",
indices: [
"Ordenado"
],
description: "placeholder"
}
}
]
}
我来发个帖子脚本:
import requests, json
url = "http://127.0.0.1/api/adley/doc"
json_data = {'value':{'item':'test'}}
response = requests.post(url, params=json_data)
print(response.text)
我看不出有什么不对我的脚本
我不明白什么是“基本”片段,或它与你的发布脚本有什么关系。 –
脚本只是在基础中插入键和值。 – Adley
工作时,我会做一个循环来插入一个特定数量的数据。 – Adley