python 中未发布数据。编译器没有给出错误

Data is not being POSTed in python. No errors given by compiler

我正在尝试 POST 数据到 api,执行后编译器没有给出任何错误,但数据没有显示在数据库中。

import requests
endpoint = "http://192.168.10.2:8085/api/customer"
myObj = {"customer_id": 900, 
    "customer_code": "qwertyuiop", 
    "ustomer_name": "lion", 
    "contact": "030190000", 
    "address": "lane"}
x = requests.post(url = endpoint, data = myObj)

编辑: 当我尝试做

print(x.text) 

我收到这个错误:

{"type":"https://tools.ietf.org/html/rfc7231#section-6.5.13","title":"Unsupported Media Type","status":415,"traceId":"00-9b47b6c7ce1f14499652ba95b3faca3a-cc8e04f53a002647-00"}

如有任何帮助,我们将不胜感激。

我发现了问题,我需要使用 json(需要字典)而不是数据(需要字符串)。

import json
import requests

payload = {"customer_id": 456, "customer_code": "fakhr", "customer_name": "fakhr", "contact": "fakhr", "address": "fakhr"}
r = requests.post("http://192.168.10.2:8085/api/customer", json=payload)
print(r.text)