adafruit / Adafruit_IO_Python

Adafruit IO Python Client Library
Other
225 stars 99 forks source link

SSL issue with example of subscribe #97

Closed soumilshah1995 closed 5 years ago

soumilshah1995 commented 5 years ago

ERROR: /usr/local/bin/python3.7 "/Users/soumilshah/IdeaProjects/MasterIoT/chrome automation/test.py" Traceback (most recent call last): File "/Users/soumilshah/IdeaProjects/MasterIoT/chrome automation/test.py", line 40, in client.connect() File "/Users/soumilshah/Library/Python/3.7/lib/python/site-packages/Adafruit_IO/mqtt_client.py", line 141, in connect keepalive=keepalive, **kwargs) File "/Users/soumilshah/Library/Python/3.7/lib/python/site-packages/paho/mqtt/client.py", line 839, in connect return self.reconnect() File "/Users/soumilshah/Library/Python/3.7/lib/python/site-packages/paho/mqtt/client.py", line 994, in reconnect sock.do_handshake() File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/ssl.py", line 1117, in do_handshake self._sslobj.do_handshake() ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:1056)


import sys
import time
import random

# Import Adafruit IO MQTT client.
from Adafruit_IO import MQTTClient

ADAFRUIT_IO_KEY = 'xx'
ADAFRUIT_IO_USERNAME = 'xx'
IO_FEED = 'onoff'

def connected(client):
    print ('Connected to Adafruit IO! Listening for feed changes...')
    # subscribe to feed in a dashdoard
    client.subscribe('onoff')

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 1:
    data = client.on_message```
brentru commented 5 years ago

Hi - I am unable to replicate this with your code and the latest version of this library. Please make sure you're running the latest version of the library and try running your code again.

> python3 subscribe.py 
Connected to Adafruit IO!
Connected to Adafruit IO! Listening for feed changes...