我正在尝试使用winpexpect中的plink连接到远程Linux服务器。我使用了以下代码:
child = winpexpect.winspawn('plink root@hostname')
child.logfile = sys.stdout
i = child.expect(['Password:')
child.expect('Password:')
child.sendline('password')我在stdout上得到的输出是:
Using keyboard-interactive authentication.
Password: password
Using keyboard-interactive authentication.
Password:
Using keyboard-interactive authentication.
Password: Traceback (most recent call last):
File "<stdin>", line 1, in <module>
...in expect_loop
raise TIMEOUT (str(e) + '\n' + str(self))
pexpect.TIMEOUT: Timeout exceeded in read_nonblocking().
...
command: plink
args: ['plink', 'root@hostname']
buffer (last 100 chars): yboard-interactive authentication.
Password:
Using keyboard-interactive authentication.
Password:
before (last 100 chars): yboard-interactive authentication.
Password:
Using keyboard-interactive authentication.
Password:
after: <class 'pexpect.TIMEOUT'>
...在Linux下的pexpect中可以使用等效的代码(将winpexpect模块替换为pexpect,将plink调用替换为ssh),因此我知道expect()匹配是正确的。看起来winpexpect正在写入屏幕,而plink没有将其注册为输入到密码字段的文本。
有人能发现这里的问题吗?
发布于 2012-09-07 16:48:53
这是一个带有错误修复的分支winexpect项目:https://bitbucket.org/weyou/winpexpect,你可以尝试一下。
发布于 2015-03-30 06:46:42
我在使用winpexpect和plink时遇到了类似的问题。This question有一个适合我的解决方案。连接到我的串行接口的设备在本地回显信息,这让winpexpect感到困惑。将sendline()替换为执行以下操作的函数:
child.send(cmd)
child.pexpect(cmd)
child.send('\n')为我修复了每一个电话。child.pexpect(cmd)在目标种子之前读取本地回显的字符,\n并开始响应。
https://stackoverflow.com/questions/7591715
复制相似问题