【问题标题】:How to send CoAP requests with Python?如何使用 Python 发送 CoAP 请求?
【发布时间】:2017-06-12 05:30:31
【问题描述】:

有没有办法使用 Python 发送 CoAP 请求,例如 HTTP 请求。我尝试了以下一项,但出现了很多错误。

rec = reuest.get(coap://localhost:5683/other/block)

【问题讨论】:

  • 我猜你的意思是requests.get? (来自requests 库)。请务必进行编辑以澄清,并包含您收到的错误消息以供未来访问者参考。 这次与解决方案并不真正相关,但minimal reproducible example 总是有助于获得好的答案。

标签: python http iot coap


【解决方案1】:

您可以使用诸如 CoAPython 之类的库来充当 CoAP 客户端:

from coapthon.client.helperclient import HelperClient

client = HelperClient(server=('127.0.0.1', 5683))
response = client.get('other/block')
client.stop()

response 的类型为 Response。响应中可用的方法列在文档中,您必须build yourself

由于您没有列出要对响应执行的操作,因此您可以使用文档找出可用的方法并获取所需的值。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-13
    • 2012-09-19
    • 2017-06-29
    • 2020-02-05
    • 2014-12-18
    • 1970-01-01
    相关资源
    最近更新 更多