gpt4 book ai didi

python telnetlib 预期错误 : TypeError: can't use a string pattern on a bytes-like object

转载 作者:太空宇宙 更新时间:2023-11-03 11:07:46 25 4
gpt4 key购买 nike

<分区>

我正在尝试将 2 个预编译的正则表达式传递给 python 的 telnetlib expect 方法,但我得到:TypeError: can't use a string pattern on a bytes-like object。示例代码如下:

import re,sys,telnetlib

tn=telnetlib.Telnet('localhost',23,10)

re_list=[re.compile("login:",re.I),re.compile("username:",re.I)]
print("re_list:",re_list)
# Expect gets errors here
index,obj,data=tn.expect(re_list,10)

示例输出如下:

python tn_exp_bug.py
re_list: [<_sre.SRE_Pattern object at 0x00A49E90>, <_sre.SRE_Pattern object at 0x00A6CB60>]
Traceback (most recent call last):
File "tn_exp_bug.py", line 8, in <module>
index,obj,data=tn.expect(re_list,10)
File "c:\python33\lib\telnetlib.py", line 652, in expect
return self._expect_with_select(list, timeout)
File "c:\python33\lib\telnetlib.py", line 735, in _expect_with_select
m = list[i].search(self.cookedq)
TypeError: can't use a string pattern on a bytes-like object</pre>

其他细节:我在 Windows XP 上运行,Python 版本 3.3.0。我检查了 bugs.python.org 并且只有 1 个 telnet 的开放错误,这似乎根本不相关。

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com