msgflo / msgflo-python

Python participant support for MsgFlo
MIT License
13 stars 3 forks source link

Allow non-JSON payloads #16

Open bergie opened 7 years ago

bergie commented 7 years ago

Currently msgflo-python fails if payloads can't be serialized as JSON:

Traceback (most recent call last):
  File "/home/bergie/.local/lib/python2.7/site-packages/gevent/greenlet.py", line 536, in run
    result = self._run(*self.args, **self.kwargs)
  File "/home/bergie/Projects/c-base/farbgeber/farbgeber.py", line 107, in loop
    self.send_palette(palette)
  File "/home/bergie/Projects/c-base/farbgeber/farbgeber.py", line 128, in send_palette
    self.send('palette', palette)
  File "/home/bergie/.local/lib/python2.7/site-packages/msgflo/msgflo.py", line 54, in send
    self._engine._send(outport, outdata)
  File "/home/bergie/.local/lib/python2.7/site-packages/msgflo/msgflo.py", line 234, in _send
    serialized = json.dumps(data)
  File "/usr/lib/python2.7/json/__init__.py", line 243, in dumps
    return _default_encoder.encode(obj)
  File "/usr/lib/python2.7/json/encoder.py", line 207, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "/usr/lib/python2.7/json/encoder.py", line 270, in iterencode
    return _iterencode(o, 0)
  File "/usr/lib/python2.7/json/encoder.py", line 184, in default
    raise TypeError(repr(o) + " is not JSON serializable")
TypeError: <Color #cc5d00> is not JSON serializable
bergie commented 7 years ago

Also would be nice to be able to send strings as-is. Now they become quoted.

So when sending hello world, the MQTT topic gets "hello world"