Python concatenating strings - UnicodeDecodeError: 'ascii' codec can't decode byte

对着背影说爱祢 提交于 2020-01-04 05:39:11

问题


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



来源:https://stackoverflow.com/questions/10597677/python-concatenating-strings-unicodedecodeerror-ascii-codec-cant-decode-by

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!