adafruit-io library not working in Python 3.9?

Moderators: adafruit_support_bill, adafruit

Forum rules
If you're posting code, please make sure your code does not include your Adafruit IO Active Key or WiFi network credentials.
Locked
User avatar
ryanlogsdon
 
Posts: 6
Joined: Thu Feb 04, 2021 1:34 pm

adafruit-io library not working in Python 3.9?

Post by ryanlogsdon »

Hi Everyone,

Could anyone help me find what I need to change to make my Python script work in Python 3.9? I've tested the exact same code in Python 3.6, 3.7, and 3.8, where it works just fine, but I get an SSL error in my newly upgraded 3.9 environment.

I'm just trying to connect to Adafruit IO, so my IoT device can subscribe to the MQTT service.

Code: Select all

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)
Error in Python 3.9:

Code: Select all

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)
Direct link to my SO post: https://stackoverflow.com/questions/663 ... 5_66362762

Thanks very much,
Ryan

User avatar
brubell
Learn User Page
 
Posts: 2017
Joined: Fri Jul 17, 2015 10:33 pm

Re: adafruit-io library not working in Python 3.9?

Post by brubell »

Are you using macOS or Windows? How did you install Python?

In the terminal, could you run:

Code: Select all

pip3 freeze 
and paste the output?

User avatar
ryanlogsdon
 
Posts: 6
Joined: Thu Feb 04, 2021 1:34 pm

Re: adafruit-io library not working in Python 3.9?

Post by ryanlogsdon »

Hi Brubell,

Code: Select all

adafruit-io==2.5.0
beautifulsoup4==4.9.3
bs4==0.0.1
certifi==2020.12.5
chardet==4.0.0
idna==2.10
paho-mqtt==1.5.1
requests==2.25.1
soupsieve==2.2
urllib3==1.26.3
I'm using a Mac, and I upgraded by grabbing a download from Python.org.

Thanks,
Ryan

User avatar
brubell
Learn User Page
 
Posts: 2017
Joined: Fri Jul 17, 2015 10:33 pm

Re: adafruit-io library not working in Python 3.9?

Post by brubell »

I'm not sure what's causing the issue.. I just tested and I'm able to run Adafruit IO Python on macOS w/Python 3.9.1.

Could you try a different computer or Wireless connection (maybe try plugging into ethernet)?

User avatar
ryanlogsdon
 
Posts: 6
Joined: Thu Feb 04, 2021 1:34 pm

Re: adafruit-io library not working in Python 3.9?

Post by ryanlogsdon »

Sorry, no I can't :(

Locked
Forum rules
If you're posting code, please make sure your code does not include your Adafruit IO Active Key or WiFi network credentials.

Return to “Internet of Things: Adafruit IO and Wippersnapper”