我试图使用python发布JSON数据(RESTful API)。
null = none
payload = {
"priority": 1,
"hello_id": 207,
"bye_id": 207,
"s1": 1,
"s2": 2,
"sub": "CHECK 123",
"t1": "Leave",
"product_id": null,
"due": "2001-01-01T06:11:54.884Z",
"tags": [
"HelloTag"
]
}
headers = {'content-type': 'application/json'}
r = requests.post(myurl, data=json.dumps(payload), headers=headers)
(OR)
r = requests.post(myurl, json = json.dumps(payload_post), headers=headers)
(OR)
r = requests.post(myurl, data = payload_post, headers=headers, auth=(username_accadmin, password_accadmin))
(OR)
r = requests.post(myurl, json=payload, headers=headers)
以上三行似乎都没有产生预期的响应(或)我在邮递员那里得到的响应。
In the response I get :
"Validation failed","errors":[{"field":"priority","message":"Unexpected/invalid field in request","code":"invalid_field"}]
(FOR ALL FIELDS IN THE JSON DATA)
为什么即使使用dumps()方法将dict()转换为JSON,数据也会出错?
注意:如果有效负载中的所有字段都是字符串,则数据将按预期发布。
data
应该是dict
或list
,而不是dumps
返回的字符串。请参阅documentation。另外,您应该在负载中使用
None
,而不是null
。相关问题 更多 >
编程相关推荐