Skip to content

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

@jamesleesaunders

Description

@jamesleesaunders

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'))

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions