-2

Is there a procedure to send HTTP POST message without hard-coding endpoint and topic name. I am able to give the message as a variable but not endpoint and Topic.

This code is working absolutely fine:

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))

But how to give topic name and AWS endpoint as variables?

1 Answers1

1

Store topic name and AWS endpoint as variables & concatenate them to form the url. Use that in the post request.

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

You can pass additional parameters in the POST request (cert, data etc.) as required.

agent420
  • 3,291
  • 20
  • 27