Python MQTT: TypeError: coercing to Unicode: need string or buffer, bool found

Posted by user2923860 on Stack Overflow See other posts from Stack Overflow or by user2923860
Published on 2013-10-26T21:19:31Z Indexed on 2013/10/26 21:54 UTC
Read the original article Hit count: 562

Filed under:
|
|
|
|

When my python code tries to connect to the MQTT broker it gives me this Type Error:

Update- I added the Complete Error

Traceback (most recent call last):
  File "test.py", line 20, in <module>
    mqttc.connect(broker, 1883, 60, True)
  File "/usr/local/lib/python2.7/dist-packages/mosquitto.py", line 563, in connect
    return self.reconnect()
  File "/usr/local/lib/python2.7/dist-packages/mosquitto.py", line 632, in reconnect
    self._sock = socket.create_connection((self._host, self._port), source_address=(self._bind_address, 0))
  File "/usr/lib/python2.7/socket.py", line 561, in create_connection
    sock.bind(source_address)
  File "/usr/lib/python2.7/socket.py", line 224, in meth
    return getattr(self._sock,name)(*args)
TypeError: coercing to Unicode: need string or buffer, bool found

The code of the python file is:

#! /usr/bin/python
import mosquitto
broker = "localhost"
#define what happens after connection
    def on_connect(rc):
        print "Connected"
#On recipt of a message do action
    def on_message(msg):
        n = msg.payload
        t = msg.topic
        if t == "/test/topic":
            if n == "test": 
        print "test message received"

# create broker
mqttc = mosquitto.Mosquitto("python_sub")
#define callbacks
mqttc.on_message = on_message
mqttc.on_connect = on_connect
#connect
mqttc.connect(broker, 1883, 60, True)
#Subscribe to topic
mqttc.subscribe("/test/topic", 2)

#keep connected
while mqttc.loop() == 0:
    pass    

I have no idea why its giving me this it work 2 days ago.

© Stack Overflow or respective owner

Related posts about python

Related posts about python-2.7