python-3.x - 如何修复 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")
解决方案
一旦我修复了它开始工作的策略,问题不在程序中,而是在 aws 端的配置中
我必须使用 iot:* 修复我的 iot 策略,该策略附加到证书上
推荐阅读
- scala - Scala:无类型的表达式。类型不确认期望类型文档
- android - 为什么我的应用在尝试连接到 Firebase 时会崩溃?
- apache-kafka - Kafka 消费者 CLI 中未显示数值
- android - 如何解析 XML 文件并使用找到的值创建对象?
- spring - 无法在 websphere 自由配置文件中创建 EntityManagerFactory
- pandas - 即使使用 inplace=True,Pandas 也无法正常工作
- reactjs - 从状态中删除对象时子组件列表未正确更新
- python - 从控制台读取未知数量的行
- c# - 如何在同一视图中创建“n”个子对象和父对象?
- wpf - 如何强制嵌入在 Expander 中的 WPF TreeView 重新排列大小?