【发布时间】:2018-08-03 15:42:40
【问题描述】:
我正在使用 Fiware Orion 上下文代理,我想使用 python 脚本发布一些数据。命令行(运行良好)如下所示:
curl -X POST -H "Accept: application/json" -H "Fiware-ServicePath: /orion" -H "Fiware-Service: orion" -H "Content-Type: application/json" -d '{"id": "JetsonTX1", "type": "sensor", "title": {"type": "Text","value": "Init"}, "percentage": { "type": "Text", "value": "0%"}}' "http://141.39.159.63:1026/v2/entities/"
我的 Python 脚本:
import requests
import json
url = 'http://141.39.159.63:1026/v2/entities/'
data = '''{
"title": {
"value": "demo",
"type": "Text"
},
"percentage": {
"type": "Text",
"value": "0%"
}'''
data_json = json.dumps(data)
headers = {"Accept": "application/json", "Fiware-ServicePath": "/bonseyes", "Fiware-Service": "bonseyes", "Content-Type": "application/json"}
response = requests.post(url, data=data_json, headers=headers)
print(response.json())
这是 response.json() 返回的内容:
{u'description': u'Errors found in incoming JSON buffer', u'error': u'ParseError'}
任何想法如何解决这个问题?
谢谢!
【问题讨论】:
-
我编辑的答案是否解决了您的问题?
-
几乎!我不得不使用:
response = requests.post(url, json=data, headers=headers)而不是response = requests.post(url, json=data_json, headers=headers)非常感谢! -
如果有帮助请标记答案
标签: python json curl python-requests fiware-orion