在Python中AWS-IoT-httppost请求?

2024-06-09 07:00:54 发布

您现在位置:Python中文网/ 问答频道 /正文

是否有一个过程来发送没有硬编码端点和主题名的httppost消息。 我可以将消息作为变量而不是端点和主题。在

这个代码运行得非常好:

import requests

caPath = "aws-iot-rootCA.crt"
certPath = "cert.pem.crt"
keyPath = "privkey.pem.crt"

parameters = (
    ('qos', '1'),
)
payload= """{
  "message": "Hello"
}"""

r = requests.post('https://******endpoint*****.us-west-2.amazonaws.com:8443/topics/TopicName',
    params=parameters,,data=payload,
    cert=(certPath,keyPath,caPath))

但是如何将主题名和AWS端点作为变量?


Tags: 消息编码主题cert过程端点requestspem
1条回答
网友
1楼 · 发布于 2024-06-09 07:00:54

将topic name和AWS端点存储为变量,并将它们连接起来以形成url。在post请求中使用它。在

endpoint='https://******endpoint*****.us-west-2.amazonaws.com:8443'
topic='TopicName'
url= endpoint+'/topics/'+topic
r= requests.post(url,params=parameters)

您可以根据需要在POST请求中传递其他参数(cert、data等)。在

相关问题 更多 >