希望使用python脚本访问orion数据(不使用curl或Postman)。下面显示了我的orion.py脚本中的python脚本:
import json
import requests
orion_endpoint="some-endpoint"
url_query=("orion_url" % (orion_endpoint))
body_dict = {
'entities': [
{
'type': 'AirQualityObserved',
'idPattern': '.*',
}
],
}
r_headers = {'Content-Type': 'application/json'}
#print(data["coordinates"][0][0])
r = requests.post(
url=url_query,
data=json.dumps(body_dict),
headers=r_headers
)
print(r.content) 运行此脚本将实体信息转储到控制台。如何使用脚本订阅通知以便通知(而不仅仅是转储上下文)?
发布于 2019-03-14 16:59:56
Orion实现了REST,因此可以使用任何能够执行HTTP请求的编程语言( Python就是其中之一,例如使用requests模块)。
要创建订阅,您可以使用相同的requests.post(),但使用不同的参数化。特别是:
url将对应于API中的订阅资源,即/v2/entities。data中的“订阅”部分,NGSIv2规范应该遵循订阅的语法。headers可以是相同的。在这种情况下,它可能会有所帮助,这个剧本展示了如何在Python中创建订阅。
https://stackoverflow.com/questions/55142367
复制相似问题