简体   繁体   中英

Python MQTT Client publish isn't handling variable

My code:

myTopic = "lab"
myPayload = ""
qos = 1
myPayload = input('Enter a message to publish: ')
myAWSIoTMQTTClient.publish(myTopic, myPayload, qos)

When I run the script, the device connects to AWS IoT, and the "Enter a message to publish:" prompt appears. I enter "hello" (no quotes) and it returns the following error:

Traceback (most recent call last):
File "customAWSIoTscript.py", line 65, in <module>
myPayload = input('Enter a message to publish: ')
File "<string>", line 1, in <module>
NameError: name 'hello' is not defined

However, when I replace the myPayload variable with a string in the function , it works fine. Likewise, if I set myPayload = "hello", it works too. Leave off the quotes myPayload = hello, and it fails.

So I've determined that myAWSIoTMQTTClient.publish is looking for a string, but why doesn't it accept the string from my input() function?

Received the answer on AWS Developer Forums. Long story short- it's a known error in AWS IoT Python SDK v1.1.0, and will be addressed next update. There is a hotfix referenced in the reply I marked as the answer.

https://forums.aws.amazon.com/thread.jspa?threadID=242462

So I guess this is just a knowledge base post for those that happen to come across my issue.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM