【发布时间】:2011-09-29 02:13:14
【问题描述】:
我正在尝试使用 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 没有将其注册为输入密码字段的文本。
谁能发现这里的问题?
【问题讨论】:
-
您找到解决方案了吗?我尝试了从 BitBucket 更改的 winpexpect 脚本,但没有成功。谢谢,克里斯
-
很遗憾,我从未找到解决方案。看起来像是 winpexpect 中的一个错误,但我没有时间自己尝试解决。