Python连接字符串-UnicodeDecodeError:'ascii'编解码器无法解码字节 [英] Python concatenating strings - UnicodeDecodeError: 'ascii' codec can't decode byte

查看:168
本文介绍了Python连接字符串-UnicodeDecodeError:'ascii'编解码器无法解码字节的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想像这样连接两个字符串:

I want to concatenate two strings like this:

requestData = command + ' ' + data

在我的情况下,数据"包含二进制数据,不应打开该二进制数据,而应将其粘贴到命令中.但是imho python试图打开它,但失败并显示:

"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?

Python 2.7 另外,我的数据实际上不是utf-8解码可能没有帮助-它的二进制数据.

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

推荐答案

尝试使用 http://docs.python.org/library/array.html (带有'B')而不是字符串

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

这篇关于Python连接字符串-UnicodeDecodeError:'ascii'编解码器无法解码字节的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆