首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用python的coap协议获取方法

使用python的coap协议获取方法
EN

Stack Overflow用户
提问于 2018-11-05 14:07:12
回答 1查看 1.2K关注 0票数 0

我试图使用coap运行一个应用程序,但我是新来的。我正在使用python coapthon3库。但是我希望使用编码路径从库中获取有效载荷。但我不能这么做。我的客户端代码如下。谢谢

代码语言:javascript
复制
from coapthon.client.helperclient import HelperClient

host = "127.0.0.1"
port = 5683
path = "encoding"
payload = 'text/plain'

client = HelperClient(server=(host, port))
response = client.get(path + 'application/xml' + '<value>"+str(payload)+"</value>')
client.stop()
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-11-06 12:53:20

不,你不应该把所有的东西连到小路上。

不幸的是,HelperClient#get没有提供指定有效负载的能力,尽管根据CoAP规范,它是相当合法的。

因此,您需要创建一个请求并填充所有需要的字段,并使用send_request方法。

我想我的片段不是毕多尼语,所以请容忍我。

代码语言:javascript
复制
from coapthon.client.helperclient import HelperClient
from coapthon.messages.request import Request
from coapthon import defines

host = "127.0.0.1"
port = 5683
path = "encoding"
payload = 'text/plain'

client = HelperClient(server=(host, port))

request = Request()
request.code = defines.Codes.GET.number
request.type = defines.Types['NON']
request.destination = (host, port)
request.uri_path = path
request.content_type = defines.Content_types["application/xml"]
request.payload = '<value>"+str(payload)+"</value>'
response = client.send_request(request)

client.stop()
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53156009

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档