Read Non Blocking error while using pxssh (ssh mod

2019-06-23 05:40发布

问题:

I am trying to do ssh on a remote machine using a python script using pxssh moudule.

Here are the lines of code that I use for the same :

    s = pxssh.pxssh()
    s.login (hostip,'root',auto_prompt_reset=False)

But this gives me the following TIMEOUT error.

  Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.6/dist-packages/pxssh.py", line 243, in login
    if not self.synch_original_prompt():
  File "/usr/local/lib/python2.6/dist-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/local/lib/python2.6/dist-packages/pexpect.py", line 824, in read_nonblocking
    raise TIMEOUT ('Timeout exceeded in read_nonblocking().')
pexpect.TIME

OUT: Timeout exceeded in read_nonblocking().

回答1:

I have changed the python library and instead using paramiko which is much more stable and doesn't give the above error.



回答2:

I had the same problem. This post ( http://bytes.com/topic/python/answers/760027-read_nonblocking-error-pxssh ) had the solution.

"I just added a self.sendline() and a time.sleep(0.5) right before the first read_nonblocking() call within synch_original_prompt()"

This solved the problem for me.



标签: python ssh