← Back to team overview

mosquitto-users team mailing list archive

Re: unicode strings

 

got you, so the following in publish():

if isinstance(payload, str) == True or isinstance(payload, bytearray) ==
True:
            local_payload = payload

should actually be something like

if payload and type(payload) in (str, unicode, bytearray):
    local_payload = payload

I guess
thanks,



Sasha Bolotnov
www.bolotnov.info



On Tue, Feb 12, 2013 at 1:20 AM, Roger Light <roger@xxxxxxxxxx> wrote:

> 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