Message.received handler throwing exception

Hello,

I have a Nova connected to my Raspberry Pi that is able to connect to the network and receive messages via CLI with no problem, but my Python script is throwing some weird exceptions that I am having a lot of trouble debugging.

I have the following code:

import serial, time
from Hologram.HologramCloud import HologramCloud

hologram = HologramCloud(dict(), network='cellular')

result = hologram.network.connect()
if result == False:
	print('Error: failed to connect to cellular network')
else:
	print('Connected to '+hologram.network_type+' v'+hologram.version)

def serial_write():
	data = hologram.popReceivedMessage()
	print(data)

hologram.openReceiveSocket()

while True:
	hologram.event.subscribe('message.received', serial_write)

hologram.closeReceiveSocket()

The script runs and connects fine, but when I send a cloud message, I get the following error:

Exception in thread Thread-2:
Traceback (most recent call last):
  File "/usr/lib/python3.7/threading.py", line 917, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.7/threading.py", line 865, in run
    self._target(*self._args, **self._kwargs)
  File "/usr/local/lib/python3.7/dist-packages/Hologram/CustomCloud.py", line 336, in __incoming_connection_thread
    recv += result
TypeError: can only concatenate str (not "bytes") to str

Could be my usage of the SDK, but basically my goal is to run this script as a daemon and forward inbound cloud messages to a Serial port. Any help is greatly appreciated, thanks.

Looks like a bug in the SDK, a simple fix but hard to notice due to the way python 3 strings are handled

I see. How should I proceed?

I can make an update to the SDK. I will do it tonight and test it a bit.

OK here is a bugfix branch if you want to give it a try: https://github.com/hologram-io/hologram-python/tree/bugfix/encoding

you can install it by doing pip3 install git+https://github.com/hologram-io/hologram-python.git@bugfix/encoding#egg=hologram-python

Thanks for the quick response. I ran the install you gave me but it said the requirement was already satisfied and it doesn’t look like anything new was installed, tried to test again and got the same error.

try uninstalling and running it. That pip command should overwrite the currently installed sdk though you might have to do sudo

Uninstalled and reinstalled and it works great now. Thanks again!

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.