Skip to content

can't concat str to bytes #3

@benbucksch

Description

@benbucksch

Environment

  • Python 3.7 or Python 3.8

Reproduction steps

  1. Bluetooth pairing
  2. python pbapclient.py
  3. connect 20:20:0F:32:D3:29 (use your device ID)

Actual result:

TypeError: can't concat str to bytes

More info, with stack:

2020-06-18 18:46:25,120 __main__ INFO     Connecting to pbap server = (20:20:0F:32:D3:29, 19)
...
  File "pbapclient.py", line 168, in do_connect
    result = self.client.connect(header_list=[headers.Target(service_id)])
  File ".../pypbap/run/lib/python3.7/site-packages/PyOBEX-0.28-py3.7.egg/PyOBEX/headers.py", line 33, in __init__
    self.data = self.encode(data)
  File ".../pypbap/run/lib/python3.7/site-packages/PyOBEX-0.28-py3.7.egg/PyOBEX/headers.py", line 48, in encode
    return struct.pack(">BH", self.code, len(data) + 3) + data
TypeError: can't concat str to bytes
EXCEPTION of type 'TypeError' occurred with message: 'can't concat str to bytes'

Expected result

2020-06-18 18:46:25,120 __main__ INFO     Connecting to pbap server = (20:20:0F:32:D3:29, 19)
2020-06-18 18:46:25,246 __main__ INFO     Connect success

Cause

service_id is given as string, and then concatenated with bytes in PyOBEX. That is now invalid in Python 3.8.

Fix

service_id must be written as bytes literal, according to PEP 3112

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