Python SDK and MTTQ Compatibility

Good Morning guys!
I’m working with the Python SDK, and I just realize I’m having some issues when I try to use the Ziti SDK and the paho.mqtt.client.

My use case is quite simple. I’m integrating some devices with the Google assistant. After you ask Google to do something, the request is sent to the IoT queue and grabbed by my script. The data collected from Google is sent to a Ziti Protected Webhook.

The Webhook is working like a charm, but in the “MTTQ client” when I do a monkeypatch I can’t connect anymore to the GCP MTTQ service as I have the following error:

Traceback (most recent call last):
  File "/app/ziti_tie_desk/TIEDesk_MTTQ.py", line 466, in <module>
    listen_for_messages()
  File "/app/ziti_tie_desk/TIEDesk_MTTQ.py", line 264, in listen_for_messages
    client = get_client()
  File "/app/ziti_tie_desk/TIEDesk_MTTQ.py", line 147, in get_client
    client = mqtt.Client(client_id=client_id)
  File "/usr/local/lib/python3.9/site-packages/paho/mqtt/client.py", line 519, in __init__
    self._sockpairR, self._sockpairW = _socketpair_compat()
  File "/usr/local/lib/python3.9/site-packages/paho/mqtt/client.py", line 244, in _socketpair_compat
    listensock.bind(("127.0.0.1", 0))
  File "/usr/local/lib/python3.9/site-packages/openziti/zitisock.py", line 58, in bind
    bindings = self._ziti_opts['bindings']
KeyError: 'bindings'
Exception ignored in: <function Client.__del__ at 0x7f2e696ac790>
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/paho/mqtt/client.py", line 603, in __del__
    self._reset_sockets()
  File "/usr/local/lib/python3.9/site-packages/paho/mqtt/client.py", line 649, in _reset_sockets
    if self._sockpairR:
AttributeError: 'Client' object has no attribute '_sockpairR'

On the other hand If I first do the MQTT connection and then I monkeypatch… I never reach the Ziti network.

Any ideas where to look to?

@natashell this look like a bug, do you mind adding an issue to our repo? Issues · openziti/ziti-sdk-py · GitHub

1 Like

Will do!
Thanks @ekoby !

Issue is here: Monkeypatch affecting MQTT connections · Issue #30 · openziti/ziti-sdk-py · GitHub