【发布时间】:2021-10-21 05:38:51
【问题描述】:
我正在尝试将 pexpect 模块(版本 4.8.0)与 Python 3.6.8 一起使用。我收到一个错误
TypeError: cannot use a string pattern on a bytes-like object
这是我的代码:
buff = BytesIO()
child = pexpect.spawn(path, args, logfile=buff, timeout=self.PASSPHRASE_TIMEOUT, **kwargs)
while True:
idx = child.expect([self.PASSPHRASE_RE,pexpect.EOF])
if idx == 0:
child.sendline(passphrase)
elif idx == 1:
child.wait()
break
我在idx = child.expect([self.PASSPHRASE_RE,pexpect.EOF]) 行中遇到错误
注意:我已经尝试过 StackOverflow 上的一些解决方案,例如:
- 在 pexpect.spawn 中传递 encoding('utf-8') 参数。
- 将 pexpect.spawn 替换为 pexpect.spawnu
但没有运气再次出现同样的错误。
请帮助我,我已经浪费了 3 天时间来解决此错误。
【问题讨论】:
标签: python python-3.x python-2.7 python-3.6 pexpect