Jump to content









Photo

MQTT - TLS/SSL certificate verify failed

tls ssl mqtt certificate

  • Please log in to reply
1 reply to this topic

#1 guillaume.caruso

guillaume.caruso

    Newbie

  • Members
  • Pip
  • 1 posts

Posted 24 September 2018 - 02:03 PM

Hello everyone, 

 

I am currently trying to publish a message on my stream topic with MQTT (using the provided example and certificate in the documentation).

When I don't use TLS, there is no problem, I can see the data correctly in my dashboard.

However, when I try to use the provided ca_certs.cert, I get the following error: 

[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:841).

 

The certificate is located next to my python code (in the same folder).

 

Did someone encounter and manage to resolve this error ? 

 

Thanks



#2 Yoleon

Yoleon

    Sugar Master

  • Members
  • PipPipPip
  • 57 posts

Posted 25 September 2018 - 08:36 AM

Hi guillaume,

We have watched the example code and we have discovered that the ca_cert it's not necessary to do a TLS connection.
I let you the fixed code and thank you for informing about the issue.

 

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Client paho-mqtt CarriotsMqttServer
# main.py
import paho.mqtt.publish as publish
from json import dumps
from ssl import PROTOCOL_TLSv1

class CarriotsMqttClient():
    host = 'mqtt.carriots.com'
    port = 1883
    auth = {}
    topic = '%s/streams'
    tls = None

    def __init__(self, auth, tls=None):
        self.auth = auth
        self.topic = '%s/streams' % auth['username']
        if tls:
            self.tls = tls
            self.port = 8883

    def publish(self, msg):
        try:
            publish.single(topic=self.topic, payload=msg, hostname=self.host, auth=self.auth, tls=self.tls, port=self.port)
        except Exception as ex:
            print(ex)


if __name__ == '__main__':
    auth = {'username': 'YOUR_APIKEY', 'password': ''}
    # tls_dict = {'tls_version': PROTOCOL_TLSv1}  # ssl version
    msg_dict = {'protocol': 'v2', 'device': 'ID_DEVELOPER_DEVICE', 'at': 'now', 'data': {'temp': 21, 'hum':58}}
    client_mqtt = CarriotsMqttClient(auth=auth)                     # non ssl version
    # client_mqtt = CarriotsMqttClient(auth=auth, tls=tls_dict)      # ssl version
    client_mqtt.publish(dumps(msg_dict))

Regards,

 

Carriots Staff







Also tagged with one or more of these keywords: tls, ssl, mqtt, certificate

1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users