连接到 Adafruit IO 时出现 SSL 证书错误

问题描述

似乎 Adafruit-io 库不适用于最新版本的 Python (3.9.1)。连接到 Adafruit IO 服务器时出现 SSL 证书错误

当我运行 Python 3.6、3.7 和 3.8 时,这段代码运行良好。

import sys
import time
from Adafruit_IO import MQTTClient      # pip install adafruit-io

ADAFRUIT_IO_KEY = 'MY_ADAFRUIT_KEY'
ADAFRUIT_IO_USERNAME = 'MY_ADAFRUIT_NAME'
IO_Feed = 'MY_Feed'

def connected(client):
    print ('Connected to Adafruit IO! Listening for Feed changes...')
    client.subscribe(IO_Feed)

def disconnected(client):
    print ('disconnect from Adafruit IO!')
    sys.exit(1)

def message(client,Feed_id,payload):
    # Feed_id or {0} represents the name of the Feed in the message to the Adafruit IO service.
    # Payload or {1} represents the value being sent.
    print ('Feed {0} recieved new vaule: {1}'.format(Feed_id,payload))

    if '{1}'.format(Feed_id,payload) == "ON":
        print("ON Worked ")
    if '{1}'.format(Feed_id,payload) == "OFF":
        print("OFF worked ")

client = MQTTClient(ADAFRUIT_IO_USERNAME,ADAFRUIT_IO_KEY)

client.on_connect    = connected
client.on_disconnect = disconnected
client.on_message    = message
client.loop_background()
client.connect()

while True:
    # publish data to the Feed here
    time.sleep(10)

我已升级到 Python 3.9.1,但出现以下连接错误

Traceback (most recent call last):
  File "/Users/ryan/Code/gdgIOT/subscribe.py",line 33,in <module>
    client.connect()
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/Adafruit_IO/mqtt_client.py",line 150,in connect
    self._client.connect(self._service_host,port=self._service_port,File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/paho/mqtt/client.py",line 941,in connect
    return self.reconnect()
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/paho/mqtt/client.py",line 1104,in reconnect
    sock.do_handshake()
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/ssl.py",line 1309,in do_handshake
    self._sslobj.do_handshake()
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_Failed] certificate verify Failed: self signed certificate in certificate chain (_ssl.c:1123)

非常感谢任何帮助!

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...