我想打开从一台服务器到另一台服务器的ssh连接,因此尝试使用pxssh模块。 运行以下代码时出现以下错误:
我的代码:
import pxssh
s = pxssh.pxssh()
if not s.login ('host','user','password'):
print "SSH session failed on login."
else:
print "SSH session login successful"
s.sendline ('ls -ltr')
s.logout()
在运行此代码时,我得到以下内容:
Traceback (most recent call last):
File "ssh.py", line 20, in <module>
if not s.login ('135.250.138.207','astro','astro'):
File "/usr/lib/python2.6/site-packages/pxssh.py", line 243, in login
if not self.synch_original_prompt():
File "/usr/lib/python2.6/site-packages/pxssh.py", line 134, in synch_original_prompt
self.read_nonblocking(size=10000,timeout=1) # GAS: Clear out the cache before getting the prompt
File "/usr/lib/python2.6/site-packages/pexpect.py", line 824, in read_nonblocking
raise TIMEOUT ('Timeout exceeded in read_nonblocking().')
pexpect.TIMEOUT: Timeout exceeded in read_nonblocking().
如何成功运行上述代码?
答案 0 :(得分:0)
self.sendline()
在第134行之前添加此内容, 在File&#34; /usr/lib/python2.6/site-packages/pxssh.py" 它按预期工作。