所以我在阅读了pexpect docs后写了以下内容:
import pexpect
from pexpect import popen_spawn
child = popen_spawn.PopenSpawn("ssh -t -t root@server1")
child.expect('password:')
child.sendline('pwd') # Send the password
现在我遇到了错误:
Traceback (most recent call last):
File "C:\ssh_exp.py", line 4, in <module>
child.expect('password:')
File "C:\Python27\lib\site-packages\pexpect\spawnbase.py", line 315, in expect
timeout, searchwindowsize, async)
File "C:\Python27\lib\site-packages\pexpect\spawnbase.py", line 339, in expect_list
return exp.expect_loop(timeout)
File "C:\Python27\lib\site-packages\pexpect\expect.py", line 102, in expect_loop
return self.eof(e)
File "C:\Python27\lib\site-packages\pexpect\expect.py", line 49, in eof
raise EOF(msg)
pexpect.exceptions.EOF: End Of File (EOF).
<pexpect.popen_spawn.PopenSpawn object at 0x0000000002BA3F98>
我已经验证了与server1的连接是否正确,并且在没有提示输入密码的情况下ssh没有关闭。我在这里找不到任何东西?
答案 0 :(得分:0)
一般情况下,如果在输出中找不到您所期望的(&#39;密码&#39;),就会发生这种情况。
在某些情况下,当服务器请求在您的计算机上安装公钥并且您应该期望&#39;(是/否)?&#39; - 如下面的输出。
主人的真实性&#39; &#39;无法建立。 ECDSA密钥指纹是x:xx:35:ae:1a:2e:69:e4:4d:b4:5e:2d:02:xx:f2:ed。 您确定要继续连接(是/否)吗?