Python 3 Pexpect - 生成问题:UnicodeDecodeError:'utf-8'编解码器无法解码位置 273 中的字节 0xff:无效的起始字节

问题描述 投票:0回答:1

在 SSH 会话期间使用 Python 3 的 Pexpect 模块中的 spawnu (UTF-8) 时,当远程计算机在输出中使用以下字符进行响应时,我遇到了问题:

ÿÿÿÿ

这是我收到的错误:

UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 273: invalid start byte

当我在收到输入之前输入

interact()
时,一切都会顺利进行,这就是为什么我认为问题出在 Spawnu 上。

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

utf-8 character-encoding python-3.3 pexpect
1个回答
3
投票

编码后添加

codec_errors='ignore'

类似:

proc = pexpect.spawn(command, timeout=timeout, maxread=maxread, logfile=context.log, encoding='utf-8', codec_errors='ignore')
© www.soinside.com 2019 - 2024. All rights reserved.