在 SSH 会话期间使用 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')