Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [paho-dev] paho-mqtt: How to publish an image file with python ?

Hi Ian,

Good point and one I meant to check. As it happens I was using python
3 in my first test. I've just repeated with python 2.7 and it was fine
as well.

Cheers,

Roger

On Tue, May 12, 2015 at 3:37 PM, Ian Craggs
<icraggs@xxxxxxxxxxxxxxxxxxxxxxx> wrote:
> It's not caused by using Python 3 on your PC is it?
>
> Ian
>
>
> On 05/12/2015 03:10 PM, Donie Leigh wrote:
>
> Thank you Roger, I tried on my laptop and it works, may be there is
> something wrong on my PC, I will check that tomorrow.
>
> 2015-05-12 19:07 GMT+08:00 Roger Light <roger@xxxxxxxxxx>:
>>
>> Hi Donie,
>>
>> I tested your code against test.mosquitto.org - using bytearray() and
>> without a username/password of course - and everything worked fine. I
>> used a mosquitto_sub subscriber and it received the image file.
>>
>> Have you also seen the paho.mqtt.publish convenience class?
>>
>> Cheers,
>>
>> Roger
>>
>>
>>
>>
>> On Tue, May 12, 2015 at 9:23 AM, Donie Leigh <donie.leigh@xxxxxxxxx>
>> wrote:
>> > Hi All,
>> >
>> > I cannot find how to publish an image with the python library, this is
>> > how I
>> > did:
>> >
>> >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
>> >
>> > import paho.mqtt.client as mqtt
>> >
>> > def on_publish(mosq, userdata, mid):
>> >     mosq.disconnect()
>> >
>> > client = mqtt.Client()
>> > client.username_pw_set('user', 'password')
>> > client.on_publish = on_publish
>> >
>> > client.connect("myvps.com", 1883, 60)
>> >
>> > f = open('1.jpg', 'rb')
>> > fileContent = f.read()
>> > byteArr = bytes(fileContent)
>> > client.publish("test", byteArr, 0)
>> >
>> > client.loop_forever()
>> >
>> > <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
>> >
>> > An error was raised:
>> >
>> > UnicodeDecodeError: 'ascii' codec can't decode byte 0xff in position 0:
>> > ordinal not in range(128)
>> >
>> > If I replace the line "byteArr = bytes(fileContent)" with "byteArr =
>> > bytearray(fileContent)", no error will be raised but the file won't be
>> > published.
>> >
>> > My mosquitto service is good and works well with mosquitto_sub and
>> > mosquitto_pub commands.
>> >
>> > _______________________________________________
>> > paho-dev mailing list
>> > paho-dev@xxxxxxxxxxx
>> > To change your delivery options, retrieve your password, or unsubscribe
>> > from
>> > this list, visit
>> > https://dev.eclipse.org/mailman/listinfo/paho-dev
>> _______________________________________________
>> paho-dev mailing list
>> paho-dev@xxxxxxxxxxx
>> To change your delivery options, retrieve your password, or unsubscribe
>> from this list, visit
>> https://dev.eclipse.org/mailman/listinfo/paho-dev
>
>
>
>
> _______________________________________________
> paho-dev mailing list
> paho-dev@xxxxxxxxxxx
> To change your delivery options, retrieve your password, or unsubscribe from
> this list, visit
> https://dev.eclipse.org/mailman/listinfo/paho-dev
>
>
> --
> Ian Craggs
> icraggs@xxxxxxxxxx                 IBM United Kingdom
> Paho Project Lead; Committer on Mosquitto
>
>
> _______________________________________________
> paho-dev mailing list
> paho-dev@xxxxxxxxxxx
> To change your delivery options, retrieve your password, or unsubscribe from
> this list, visit
> https://dev.eclipse.org/mailman/listinfo/paho-dev


Back to the top