【问题标题】:Python 3 Pexpect - spawnu issue: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 273: invalid start bytePython 3 Pexpect - spawnu 问题:UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 273: invalid start byte
【发布时间】:2016-10-11 19:29:19
【问题描述】:

我在 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】:

    编码后添加codec_errors='ignore'

    类似:

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

    【讨论】:

      猜你喜欢
      • 2021-11-24
      • 1970-01-01
      • 1970-01-01
      • 2020-12-26
      • 2020-01-31
      • 1970-01-01
      • 2018-10-15
      • 2020-03-12
      • 2022-09-26
      相关资源
      最近更新 更多