Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

handler.py: missing 1 required positional argument: 'properties' #68

Closed
nicola-lunghi opened this issue Nov 11, 2019 · 3 comments
Closed

Comments

@nicola-lunghi
Copy link

Following the example on the README i have a connect function defined like this (I'm not using

import asyncio
import os
import signal
import time

from gmqtt import Client as MQTTClient
from gmqtt.mqtt.constants import MQTTv311

host = 'localhost'
port = '1993'

STOP = asyncio.Event()


def on_connect(client, flags, rc, properties):
    print('Connected')
    client.subscribe('#', qos=0)


def on_message(client, topic, payload, qos, properties):
    print('RECV MSG:', payload)


def on_disconnect(client, packet, exc=None):
    print('Disconnected')


def on_subscribe(client, mid, qos):
    print('SUBSCRIBED')


def ask_exit(*args):
    STOP.set()


async def main(broker_host, broker_port):
    client = MQTTClient("client-id")

    client.on_connect = on_connect
    client.on_message = on_message
    client.on_disconnect = on_disconnect
    client.on_subscribe = on_subscribe

    await client.connect(broker_host, broker_port, version=MQTTv311)
    await STOP.wait()
    await client.disconnect()


if __name__ == '__main__':
    loop = asyncio.get_event_loop()

    loop.add_signal_handler(signal.SIGINT, ask_exit)
    loop.add_signal_handler(signal.SIGTERM, ask_exit)

    loop.run_until_complete(main(host, port))

Traceback (most recent call last):
  File "/usr/lib/python3.7/site-packages/gmqtt/mqtt/handler.py", line 227, in __call__
    result = self._handle_packet(cmd, packet)
  File "/usr/lib/python3.7/site-packages/gmqtt/mqtt/handler.py", line 124, in _handle_packet
    handler(cmd, packet)
  File "/usr/lib/python3.7/site-packages/gmqtt/mqtt/handler.py", line 179, in _handle_connack_packet
    self.on_connect(self, flags, result)
TypeError: on_connect() missing 1 required positional argument: 'properties'

This will go away if I define the function as

def on_connect(client, flags, rc, properties=None):
    print('Connected')
    client.subscribe('#', qos=0)
@Lenka42
Copy link
Collaborator

Lenka42 commented Nov 12, 2019

Hi @nicola-lunghi which gmqtt version do you use? As I see by your traceback, it's outdated, please upgrade to newest gmqtt==0.4.4 version

@nicola-lunghi
Copy link
Author

I think I got the latest from pypi but I'll double check thanks

@nicola-lunghi
Copy link
Author

You were right I was using 0.0.12.
Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants