Error publishing when payload is not a string
Bug #1026638 reported by
Roland de Boo
This bug affects 1 person
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
mosquitto |
Fix Released
|
Undecided
|
Unassigned |
Bug Description
Hi,
I've noticed that when I try to publish a message with a float or int, there is an error.
This occurs in line 670 of mosquitto.py which is
if payload != None and len(payload) > 268435455:
And float / int do not have the len() method defined.
I can workaround by converting with str() before passing to the publish() method. However, I think it should either be done inside the publish() method, or a safer way for determining the length of the payload needs to be used.
Best regards,
Roland
Changed in mosquitto: | |
status: | Fix Committed → Fix Released |
To post a comment you must log in.
This is an interesting problem. The way I see it there are two approaches. The first is to use str() as you say and the second is to use struct.pack() to convert the int/float into a string/bytearray. The struct.pack option will be best in some situations because you end up dealing with int/float byte representations rather than a string representations of the numbers. The problem of course is that it is not possible for publish() to know what size of int/float you wish to generate nor what endian to use (although network endian is the logical choice of course).
I think the best solution is to use str() internally if the user passes an int/float and to also add a note to use struct.pack() before passing your data to publish() if you want a more size efficient result.
Thanks for the feedback!