我正在尝试在 winpexpect 中使用 plink 连接到远程 Linux 服务器。我正在使用以下代码:
child = winpexpect.winspawn('plink root@hostname')
child.logfile = sys.stdout
i = child.expect(['Password:')
child.expect('Password:')
child.sendline('password')
我在标准输出上得到的输出是:
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中工作(用pexpect替换winpexpect模块,用ssh替换plink调用),所以我知道expect()匹配是正确的。看起来 winpexpect 正在写入屏幕,而 plink 没有将其注册为输入密码字段的文本。
任何人都可以在这里发现问题吗?