我试图使用coap运行一个应用程序,但我是新来的。我正在使用python coapthon3库。但是我希望使用编码路径从库中获取有效载荷。但我不能这么做。我的客户端代码如下。谢谢
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()发布于 2018-11-06 12:53:20
不,你不应该把所有的东西连到小路上。
不幸的是,HelperClient#get没有提供指定有效负载的能力,尽管根据CoAP规范,它是相当合法的。
因此,您需要创建一个请求并填充所有需要的字段,并使用send_request方法。
我想我的片段不是毕多尼语,所以请容忍我。
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()https://stackoverflow.com/questions/53156009
复制相似问题