py:pexpect:error: must be one of: type 'unicode'

结论: (作为使用py2.7的)你应该使用pexpect.spawn

而非: pexpect.spawnu, 这是python3 的


当时报错如下


{19-01-12 19:10}pauldeMacBook-Pro:~/code/openssl_tar_test paul% ./pe_test.py
Traceback (most recent call last):
  File "./pe_test.py", line 11, in <module>
    child.expect('(?i)password')
  File "/Library/Python/2.7/site-packages/pexpect/spawnbase.py", line 339, in expect
    compiled_pattern_list = self.compile_pattern_list(pattern)
  File "/Library/Python/2.7/site-packages/pexpect/spawnbase.py", line 237, in compile_pattern_list
    self._pattern_type_err(p)
  File "/Library/Python/2.7/site-packages/pexpect/spawnbase.py", line 188, in _pattern_type_err
    for ast in self.allowed_string_types])
TypeError: got <type 'str'> ('(?i)password') as pattern, must be one of: <type 'unicode'>, pexpect.EOF, pexpect.TIMEOUT

我在这里找到答案

https://github.com/pexpect/pexpect/blob/master/examples/ftp.py

# Note that, for Python 3 compatibility reasons, we are using spawnu and
# importing unicode_literals (above). spawnu accepts Unicode input and
# unicode_literals makes all string literals in this script Unicode by default.
child = pexpect.spawnu('ftp ftp.openbsd.org')

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值