Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

can't concat str to bytes #3

Open
benbucksch opened this issue Jun 18, 2020 · 3 comments
Open

can't concat str to bytes #3

benbucksch opened this issue Jun 18, 2020 · 3 comments

Comments

@benbucksch
Copy link
Contributor

benbucksch commented Jun 18, 2020

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

@benbucksch
Copy link
Contributor Author

Fixed in PR #4.

@benbucksch benbucksch mentioned this issue Jun 18, 2020
@benbucksch
Copy link
Contributor Author

benbucksch commented Jun 18, 2020

Unfortunately, there are more bugs of this kind. After running pull_vcard_listing telecom/pb:

File ".../pypbap/run/lib/python3.7/site-packages/cmd2-0.8.8-py3.7.egg/cmd2.py", line 615, in new_func
    result = func(instance, arg, opts)
  File "pbapclient.py", line 218, in do_pull_vcard_listing
    list_startoffset=opts.start_offset)
  File "pbapclient.py", line 65, in pull_vcard_listing
    application_parameters = headers.App_Parameters(data, encoded=False)
  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 ".../phone/pypbap/pbapheaders.py", line 149, in extended_encode
    data += item.data
TypeError: can only concatenate str (not "bytes") to str
EXCEPTION of type 'TypeError' occurred with message: 'can only concatenate str (not "bytes") to str'

@benbucksch
Copy link
Contributor Author

Fixed the latter and one more bug as well in PR #4.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant