我正在尝试使用 Python 将一些数据加载到 ML 中。这工作正常,但类型在 ML 中设置为“T”而不是“J”。 我想解决这个问题。标题设置似乎只是为了显示,那么我该怎么做?
# Sending data
data = {'meting': '477', 'bericht': '473', 'plant': '01'}
url = 'http://server:8000/v1/documents?database=thijsPlantjes&extension=json'
headers = {'Content-Type': 'application/json'}
r = requests.post(url, json = json.dumps(data), auth=HTTPDigestAuth('plantje', 'password'), headers = headers)
最佳答案
如果使用json
参数, requests
将为您序列化,因此您不需要自己 json.dumps
。
它还会为你设置内容类型;您可以删除 headers
关键字参数。
r = requests.post(url, json=data, auth=HTTPDigestAuth('plantje', 'password'))
Instead of encoding the dict yourself, you can also pass it directly using the
json
parameter (added in version 2.4.2) and it will be encoded automatically:
关于python - 使用 Python 加载 JSON 请求错误类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33822798/