mosquitto-users team mailing list archive
-
mosquitto-users team
-
Mailing list archive
-
Message #00178
Re: unicode strings
Hi
> I'm now using a dirty walkaround:
>
> def send_message(self, topic, message):
> if type(message) == unicode:
> message = str(message).encode('string_escape')
> result, some_number = Client.mc.publish(topic, message)
mosquitto.py does actually support python 2.7 unicode data types later
down the line, it just rejects them at the publish() call by mistake.
For both python 2.7 and python 3, the _send_publish() function calls
message.encode('utf-8') to encode as utf-8. If you want to use a
different encoding just call message.encode('.....') before passing it
to the publish() call.
Cheers,
Roger
Follow ups
References