所以我已经尝试了几个模块pxssh,pexpect等,我似乎无法获得ssh连接到我们的ssh代理工作。基本上我想做的是使用我们的SSH代理,它可以访问我们其余的设备作为其他设备的跳转点,然后运行命令。这工作在ipython中,但是当它连接时会引发下面列出的异常,但是它继续执行其余的命令并且工作正常。但是,当只是作为python脚本运行时,它只会导致脚本失败。由于例外,我认为这是失败的。有没有办法关闭这个例外,或者避免这种例外?还是我这样做全错了?pxssh连接到一个ssh代理; read_nonblocking()中超时超时
我也试图与提示设置和auto_prompt_reset设置搞乱......
代理主机是不是一个真正的Linux主机,或Cisco对于这个问题,这可能是为什么违约设置不工作。
不确定该从哪里出发,所以任何帮助或见解都会很棒。
import pxssh
s = pxssh.pxssh()
hostname = '10.10.10.4'
username = 'username'
password = 'password!'
s.login (hostname, username, password)
s.sendline ('connect 10.10.5.1')
s.prompt(timeout=2)
print s.before
s.endline ('')
s.sendline ('show run')
s.prompt(timeout=2)
print s.before
发布的异常。
In [40]: s.login (hostname, username, password)
---------------------------------------------------------------------------
TIMEOUT Traceback (most recent call last)
<ipython-input-40-51f00f2075f5> in <module>()
----> 1 s.login (hostname, username, password)
/usr/lib/python2.7/dist-packages/pxssh.pyc in login(self, server, username, password, terminal_type, original_prompt, login_timeout, port, auto_prompt_reset)
241 self.close()
242 raise ExceptionPxssh ('unexpected login response')
--> 243 if not self.synch_original_prompt():
244 self.close()
245 raise ExceptionPxssh ('could not synchronize with original prompt')
/usr/lib/python2.7/dist-packages/pxssh.pyc in synch_original_prompt(self)
132 # If latency is worse than these values then this will fail.
133
--> 134 self.read_nonblocking(size=10000,timeout=1) # GAS: Clear out the cache before getting the prompt
135 time.sleep(0.1)
136 self.sendline()
/usr/lib/python2.7/dist-packages/pexpect.pyc in read_nonblocking(self, size, timeout)
822 raise EOF ('End of File (EOF) in read_nonblocking(). Very pokey platform.')
823 else:
--> 824 raise TIMEOUT ('Timeout exceeded in read_nonblocking().')
825
826 if self.child_fd in r:
TIMEOUT: Timeout exceeded in read_nonblocking().