在python 2.7中使用telnet.expect的问题
我正在尝试telnet到远程服务器,并尝试获取响应 我在前面使用了在python 2.7中使用telnet.expect的问题,python,Python,我正在尝试telnet到远程服务器,并尝试获取响应 我在前面使用了telnet.read_,直到匹配是否出现提示/模式,但是read_,直到返回所有内容,即使没有匹配。我曾想过使用telnet.expect,但我遇到了一个错误 下面是代码 com = re.compile("\#") # is the prompt tn.write("somecommand" + "\n") res = tn.expect(com, 10) 我得到的错误是 File "reg.txt", line 23,
telnet.read_,直到
匹配是否出现提示/模式,但是read_,直到返回所有内容,即使没有匹配。我曾想过使用telnet.expect
,但我遇到了一个错误
下面是代码
com = re.compile("\#") # is the prompt
tn.write("somecommand" + "\n")
res = tn.expect(com, 10)
我得到的错误是
File "reg.txt", line 23, in login
res = tn.expect(com, 10)
File "C:\Python27\lib\telnetlib.py", line 593, in expect
list = list[:]
TypeError: '_sre.SRE_Pattern' object is not subscriptable
telnetlib.expect()
发件人:
expect(列表,超时=无)
读取,直到正则表达式列表中的一个匹配为止
第一个参数是已编译(regex对象)或未编译(字节字符串)的正则表达式列表。可选的第二个参数是超时,以秒为单位;默认设置为无限期阻止
[……]
应该有效(差异是expect([com])
,而不是expect(com)
)
com = re.compile("\#") # is the prompt
tn.write("somecommand" + "\n")
res = tn.expect([com], 10)