POST:是否需要序列化JSON数据

POST: Is it necessary to serialise the JSON data

我的休息 API 在发布 JSON 数据时工作得很好。
我在服务器上使用这个:

req = request.get_json()
dicti = json.loads(req)
#It(dicti) is then processed.

在客户端,我这样进行(使用 python 请求):

dat = {'a':1, 'b':2}
serialised_dat = json.dumps(dat)
headers = {'Content-type': 'application/json', 'Accept': 'text/plain'}
requests.post("myurl", json = serialised_dat, headers = headers)

而且,一切正常。但是,当我从失眠等其他客户那里测试我的休息 API 时,
我收到内部服务器错误,这很正常,因为我粘贴到那里的 json 没有序列化。
我是否需要序列化我的 json 然后将其粘贴到其他客户端才能成功?或者
方法本身,上面,我用来发送 json 到烧瓶错误吗?

json 参数的值应该是一个将为您序列化的对象。

requests.post("myurl", json=dat, headers=headers)

如果您有预序列化数据,请改用 data 关键字参数。

requests.post("myurl", data=json.dumps(dat), headers=headers)