【发布时间】:2021-10-03 11:23:22
【问题描述】:
我一直致力于使用请求通过 API 上传数据。我之前已经成功完成了 GET 请求,但这是我第一次执行 PUT。这是一场战斗,进展缓慢而稳定,但我真的遇到了这个错误。
{"error":{"code":400,"message":"Bad Request. Missing header (Content-Type: application/json)"}}
似乎清楚地表明我在我的标题中缺少内容类型,但正如您在下面看到的,我确实将它包含在标题中。任何见解将不胜感激。
def api_put():
url = 'xxxxx'
headers = { 'Host': 'xxxxx',
'X-Api-Key': 'xxxxx',
'Content-Type': 'application/json'}
payload = { 'docType': 'jts',
'version': '1.0',
'header' : {
'columns': {
'0': {
'series': 'Longitude',
'name': 'Longitude',
'dataType': 'NUMBER'},
'1': {
'series': 'Latitude',
'name': 'Latitude',
'dataType': 'NUMBER'}},
'data': [{
'ts': '2021-07-26T15:36:02Z',
'f': { '0': {'v': 47.667196253284175},
'1': {'v': -122.38602397890254}}
}]}}
response = requests.put(url, headers=headers, data=json.dumps(payload))
print(response.text)
【问题讨论】:
标签: python python-3.x python-requests put