Python 2.7 Python Fiware Orion上下文代理问题

Python 2.7 Python Fiware Orion上下文代理问题,python-2.7,entity,fiware,fiware-orion,Python 2.7,Entity,Fiware,Fiware Orion,我无法创建实体 有效载荷: datos = { "id": "1", "type": "Car" } 查询: jsonData = json.dumps(datos) url = 'http://130.206.113.177:1026/v2/entities' response = requests.post(url, data=jsonData, headers=head) 错误: “{”error:“BadRequest”,

我无法创建实体

有效载荷:

datos = {
            "id": "1",
            "type": "Car"      
}
查询:

jsonData = json.dumps(datos)
url = 'http://130.206.113.177:1026/v2/entities'

response = requests.post(url, data=jsonData, headers=head)
错误:


“{”error:“BadRequest”,“description:”属性必须是JSON对象,除非使用了keyValues选项“}”

您是否定义了head对象?我没有看到您提供的代码中定义了它

我的直觉是,您忘了定义标题“内容类型”,该标题必须使用以下值定义:

"Content-Type": "application/json"
另一方面,以下面的方式定义标题对我来说非常有效,即使使用您在问题描述中指出的Orion实例

import json
import requests

head = {"Content-Type": "application/json"}

datos = { "id": "1", "type": "Car"}

jsonData = json.dumps(datos)
url = 'http://130.206.113.177:1026/v2/entities'

response = requests.post(url, data=jsonData, headers=head)

print response
请注意,如果按原样调用示例,可能会返回错误HTTP422,因为该对象已经存在(我在测试期间创建的对象)

问候