utf-8 - Python 3 Pexpect - spawnu 问题 : UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 273: invalid start byte

标签 utf-8 character-encoding python-3.3 pexpect

当远程机器在输出中使用以下字符进行响应时,在 SSH session 期间使用 Python 3 的 Pexpect 模块中的 spawnu (UTF-8) 时出现问题:

ÿÿÿÿ

这是我收到的错误:
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 273: invalid start byte

当我抛出 interact()在我收到输入之前,一切正常,这就是为什么我认为问题出在 spawnu 上。

我正在寻找解决方法或替代方法。

最佳答案

添加 codec_errors='ignore'编码后

就像是:

proc = pexpect.spawn(command, timeout=timeout, maxread=maxread, logfile=context.log, encoding='utf-8', codec_errors='ignore')

关于utf-8 - Python 3 Pexpect - spawnu 问题 : UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 273: invalid start byte,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39985181/

相关文章:

php - 导出到 Excel 时出现奇怪的字符

c++ - utf-8 中 std::string 的子字符串? C++11

html - 编码错误 : why does my medium sized dash is differently encoded on another server?

python - 什么是IndexError?我不断得到它

python - Argparse:如何接受具有不同 "types"的参数

asp-classic - 将 FileSystemObject 保存为 UTF

mysql - MySQL 能否自动指定 `_utf8` 以插入 UTF-8 列?

java - 如何在java中解决UTF-8

PHP输出文本图像字符编码错误

python - Python 3.3 中的哈希函数在 session 之间返回不同的结果