M
M
Mikhail Emelyanov2022-02-22 09:11:08
Python
Mikhail Emelyanov, 2022-02-22 09:11:08

What should I do to connect to the mqtt.cloud.yandex.net MQTT broker in Python?

I am writing a Python program to work with an MQTT broker.

First, I connect via port 1883 to the broker.emqx.io broker:

mqtt_broker = "broker.emqx.io"
mqtt_broker_port = 1883
mqtt_client_id = f"ozna_ds_publisher_{random.randint(0, 1000000)}"
mqtt_keepalive = 5 * 60

client = mqtt_client.Client(mqtt_client_id)
client.connect(mqtt_broker, mqtt_broker_port, keepalive=mqtt_keepalive)

Everything works fine.

At the request of the customer, I am trying to switch from broker.emqx.io to mqtt.cloud.yandex.net while switching to port 8883. From the Yandex reference materials, I did not understand which certificate I need to pass to client.tls_set () on my part, so everything predictably does not work.

The code is something like this:
mqtt_broker = "mqtt.cloud.yandex.net"
mqtt_broker_port = 8883
mqtt_client_id = f"ozna_ds_publisher_{random.randint(0, 1000000)}"
mqtt_keepalive = 5 * 60

client = mqtt_client.Client(mqtt_client_id)
client.tls_set("C:/Works/mqtt-rest-bridge/cert.pem", tls_version=ssl.PROTOCOL_TLSv1_2)
client.tls_insecure_set(True)
client.connect(mqtt_broker, mqtt_broker_port, keepalive=mqtt_keepalive)


The client.connect line throws an exception "[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:997)"

I would be grateful for a working example of connecting to the Yandex MQTT broker in Python or for clarifying which one a certificate (registry, device, or some other) must be passed to client.tls_set()

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question