【问题标题】:Accessing Orion CB with python script使用 python 脚本访问 Orion CB
【发布时间】:2019-03-13 12:51:53
【问题描述】:

希望使用 python 脚本访问 orion 数据(不使用 curl或 Postman)。下面显示我的orion.pyscript 中的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) 

运行此脚本会将实体信息转储到控制台。如何使用脚本订阅通知以便收到通知(不仅仅是转储上下文)?

【问题讨论】:

    标签: python fiware fiware-orion


    【解决方案1】:

    Orion Context Broker 实现了一个 REST API,因此可以使用任何能够执行 HTTP 请求的编程语言(Python 就是其中之一,例如使用 requests 模块)。

    要创建订阅,您可以使用相同的requests.post(),但参数化不同。特别是:

    • url 将对应 API 中的订阅资源,即/v2/entities
    • 根据NGSIv2 specification 中的“订阅”部分,data 应遵循订阅的语法。
    • headers 可以相同。

    如果有帮助,this script 展示了如何在 Python 中创建订阅。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-08-24
      • 2020-02-17
      • 2020-02-29
      • 2023-01-28
      • 2017-06-14
      相关资源
      最近更新 更多