首页 > 解决方案 > 如何修复 AWSIoTPythonSdk.exception.AWSIoTException.subscribeTimeoutException

问题描述

我正在尝试运行脚本以连接到 aws 上的 iot 主题,该主题具有客户消息回调,但连接不会发生并引发问题中提到的错误

这适用于使用 aws iot 订阅主题并接收自定义消息的树莓派 我已经检查了端点是否正确我只给出了下面的部分代码

这是错误

# Custom MQTT message callback
def photoVerificationCallback(client, userdata, message):
print("Received a new message: ")
data = json.loads(message.payload)
try:
    similarity = data[1][0]['Similarity']
    print("Received similarity: " + str(similarity))
    if(similarity >= 90):
        print("Access allowed, opening doors.")
        print("Thank you!")
except:
    pass
print("Finished processing event.")

def checkRFIDNumber(rfidnumber):
return rfidnumber == '0004098554'

# Connect and subscribe to AWS IoT
myAWSIoTMQTTClient.connect()
myAWSIoTMQTTClient.subscribe("rekognition/result", 1, 
photoVerificationCallback)
time.sleep(2)


# Publish to the same topic in a loop forever
while True:
print("waiting..")
scan = waitForRFIDScan()
print(scan)
if(checkRFIDNumber(scan)):
    print("RFID correct, taking photo...")
    uploadToS3(scan)
else:
    print("Bad RFID - Access Denied")

标签: python-3.xamazon-web-servicesmqttaws-iot

解决方案


一旦我修复了它开始工作的策略,问题不在程序中,而是在 aws 端的配置中

我必须使用 iot:* 修复我的 iot 策略,该策略附加到证书上


推荐阅读