Python concatenating strings - UnicodeDecodeError:

2019-07-10 09:03发布

问题:

I want to concatenate two strings like this:

requestData = command + ' ' + data

"data" in my case holds binary data, that should not be opened - it should just glue it to command. But imho python is attempting to open it and it fails with:

UnicodeDecodeError: 'ascii' codec can't decode byte 0xbc in position 1: ordinal not in range(128)

Is there a way to glue it without opening?

Edit: Python 2.7 Also my data is actualy not utf-8 decode might not help - its binary data.

回答1:

Try using http://docs.python.org/library/array.html (with 'B') instead of string