niolabs / python-xbee

Python tools for working with XBee radios
MIT License
101 stars 45 forks source link

base.py packet += data 'can't concat bytes to str' #50

Closed jamesleesaunders closed 7 years ago

jamesleesaunders commented 7 years ago

Possible issue with sending AT commands with Python3 in _build_command().

The following code: self._xbee.send('at', command='MY')

Running on python3 causes error:

  File "../pyalertme/base.py", line 119, in read_addresses
    self._xbee.send('at', command='MY')
  File "/usr/local/lib/python3.5/site-packages/xbee/base.py", line 394, in send
    self._write(self._build_command(cmd, **kwargs))
  File "/usr/local/lib/python3.5/site-packages/xbee/base.py", line 212, in _build_command
    packet += data
TypeError: can't concat bytes to str

Think caused by:

packet = b''
...
...
# Add the data to the packet, if it has been specified.
# Otherwise, the parameter was of variable length, and not given.
if data:
    packet += data

A cheeky workaround is to do: self._xbee.send('at', command=str.encode('MY'))