Skip to content

Commit c2c9caa

Browse files
committed
mqtt: Fix json decode under Python 3
1 parent 3a3bcd3 commit c2c9caa

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

msgflo/msgflo.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -326,17 +326,19 @@ def _on_message(self, client, userdata, mqtt_msg):
326326
port = inport['id']
327327

328328
def notify():
329-
msg = Message(mqtt_msg.payload)
330-
try:
331-
msg.json = json.loads(mqtt_msg.payload)
332-
msg.data = msg.json # compat
333-
except ValueError as e:
334-
# Not JSON, assume binary
335-
msg.json = e
336-
msg.data = msg.buffer
337-
338-
logger.debug('Delivering message to %s' % port)
339-
self.participant.process(port, msg)
329+
msg = Message(mqtt_msg.payload)
330+
try:
331+
msg.json = json.loads(mqtt_msg.payload.decode('utf8'))
332+
msg.data = msg.json # compat
333+
except ValueError as e:
334+
# Not JSON, assume binary
335+
msg.json = e
336+
msg.data = msg.buffer
337+
except Exception as e:
338+
logger.debug('unknown error %s' % str(e))
339+
340+
logger.debug('Delivering message to %s' % port)
341+
self.participant.process(port, msg)
340342

341343
gevent.spawn(notify)
342344

0 commit comments

Comments
 (0)