Comments (5)
Yes, it is not an issue with the asyncio-mqtt, just in the example code.
Anyway it's handling the exception with your changes :)
So i think you should add that change to README.md
from aiomqtt.
Anyway it's handling the exception with your changes :)
That's great to hear. I consider this issue solved then. :)
So i think you should add that change to README.md
Already done!
from aiomqtt.
Thank you for reporting this issue. Let me have a look. :)
You're right, Python's bytes.decode
function assumes that the binary represents an UTF8-encoded string per default. If the message.payload
(bytes
) object does not follow this assumption, decode
will raise an exception.
Whether the MQTT message payload is UTF8-encoded text, audio data, video frames, or even empty is completely up to the application (i.e., your usage of MQTT). The asyncio-mqtt does not impose any restrictions here.
In the example code, I have assumed that the message payload is UTF8-encoded text. This was done to make the example code a simple starting point for many applications. In your case, it seems that this assumption led to headaches. Sorry about that.
I can see two options here:
- Add a comment to the example code about the UTF8-encoded text assumption.
- Change the example code to simply display the raw binary data (without the
bytes.decode
call). The output will be more messy like this but at least it won't make assumptions about the payload.
What do you think? Do you have a third option in mind?
from aiomqtt.
Thank you for your response.
My point was more about the exception handling.
If any exception will occur in this block of code the code will just hang up.
Regarding the decoding, I think that adding a comment will be enough :)
Right now i implemented this in other way:
async def start_mqtt_client():
async with Client(
hostname=config.mqtt.server) as client:
tasks = []
tasks.append(asyncio.create_task(handle_bcg(
client.filtered_messages("/filter1"))))
tasks.append(asyncio.create_task(handle_sts(
client.filtered_messages("/filter2"))))
await client.subscribe("/topic1")
await client.subscribe("/topic2")
await asyncio.gather(*tasks)
from aiomqtt.
Thanks for the follow-up with additional details.
My point was more about the exception handling.
If any exception will occur in this block of code the code will just hang up.
Ah, I see. I could reproduce this behaviour in the advanced example from README.md. I assume that your code is closely based on the advanced example.
I think that is not an issue with asyncio-mqtt itself but with the example code. Specifically, I think that I made a mistake in the cancel_tasks
helper function.
Can you please try to apply the following change:
async def cancel_tasks(tasks):
for task in tasks:
if task.done(): # Added
continue # Added
task.cancel()
try:
await task
except asyncio.CancelledError:
pass
Again thanks for reporting this issue. :)
from aiomqtt.
Related Issues (20)
- Impossible to reuse client in case of connection timeout HOT 7
- Typing warnings in IDE on Client methods HOT 2
- AttributeError: module 'aiomqtt' has no attribute '__version__'
- session persistence with protocol version 5 HOT 1
- Pin Paho to <2.0 HOT 2
- Make aiomqtt compatible with paho v2 HOT 10
- Topic.matches should be used when doing == HOT 4
- How to get the IP of a failed connection attempt
- strange reconnection HOT 2
- MQTT broker reports a disconnection/reconnection... but no aiomqtt.MqttError is raised HOT 4
- Exceptions on __aenter__ not handled. HOT 2
- Reconnect Bug HOT 1
- Cannot instantiate a client due to internal mqtt problem HOT 2
- Issues with uvicorn on Windows 10 HOT 5
- [BUG] Cannot install version 2.0.0 with paho-mqtt 2.0.0 HOT 2
- [BUG] 127.0.0.1/localhost Work Incorrectly HOT 3
- Do not send messages for a long time mqtt automatically disconnects HOT 1
- Can't read incoming messages in pytests HOT 8
- No convenient way to get message without getting locked into a for loop HOT 2
- Can aiomqtt queue has a ring buffer option, for high frequense in-comming messages? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from aiomqtt.