empicano / aiomqtt

The idiomatic asyncio MQTT client
https://aiomqtt.bo3hm.com
BSD 3-Clause "New" or "Revised" License
427 stars 75 forks source link

'Client' object has no attribute 'message_retry_set' error when creating client and establishing conenction #327

Closed ani-rudh closed 2 months ago

ani-rudh commented 2 months ago

I tried the example with my own broker details using this code:

import asyncio
import asyncio_mqtt as aiomqtt

async def listen():
    async with aiomqtt.Client(hostname='myhost', port=1883, username='un', password='pw') as client:
        async with client.messages() as messages:
            await client.subscribe("humidity/#")
            async for message in messages:
                print(message.payload)

async def main():
    # Wait for messages in (unawaited) asyncio task
    loop = asyncio.get_event_loop()
    task = loop.create_task(listen())
    # This will still run!
    print("Magic!")
    # If you don't await the task here the program will simply finish.
    # However, if you're using an async web framework you usually don't have to await
    # the task, as the framework runs in an endless loop.
    await task

asyncio.run(main())

and I get 'Client' object has no attribute 'message_retry_set' on client.py, line 349 of the library.

Any ides how to solve or is there anything wrong I do when initializing the client?

empicano commented 2 months ago

Hi there! 🙂

It seems like you're running a 0.* version of aiomqtt (which was then still called asyncio_mqtt). Earlier version of aiomqtt specified the underlying paho-mqtt dependency as paho-mqtt>=1.6.0 which led to problems with the release of paho-mqtt 2.0. I believe that's where your issue comes from.

I would try to either (1) pin paho-mqtt manually to <2.0 or (2) update aiomqtt to a newer version.

Let me know if that helps!

ani-rudh commented 2 months ago

Hi,

yes. I can confirm that updating to latest aiomqtt fixes it.

I stumbled upon that before reading the comment when I ran the example with default connection and a notice was printed saying aiomqtt has been released, replacing this library.

Would be helpful if the pypi page mentions that 😊

empicano commented 2 months ago

I'm glad it worked! Thanks for reporting back 👍