read_nonblocking error in pxssh

Jinno jeremiah.jinno at gmail.com
Fri Feb 1 19:31:51 EST 2008


On Feb 1, 10:49 am, kayvansyl... at gmail.com wrote:
> On Jan 16, 9:24 am, jrpfinch <jrpfi... at gmail.com> wrote:
>
>
>
> > I'm attempting to use thepxsshto execute commands on a remote
> > machine and do stuff with the output.  Both machines are running SSH
> > Version Sun_SSH_1.0, protocol versions 1.5/2.0 and Intel Solaris 9.
>
> > I am hitting a problem with read_nonblocking in the pexpect module as
> > follows:
>
> > >>> importpxssh
> > >>> s=pxssh.pxssh()
> > >>> s.login("myhost","root","mypass")
>
> > Trying command: ssh -q -l root gerard
> > Expect returned i=2
> > Expect returned i=1
> > Traceback (most recent call last):
> >   File "<stdin>", line 1, in <module>
> >   File "pxssh.py", line 244, in login
> >     if not self.synch_original_prompt():
> >   File "pxssh.py", line 134, in synch_original_prompt
> >     self.read_nonblocking(size=10000,timeout=10) # GAS: Clear out the
> > cache before getting the prompt
> >   File "/opt/python2.5.1/lib/python2.5/site-packages/pexpect.py", line
> > 824, in read_nonblocking
> >     raise TIMEOUT ('Timeout exceeded in read_nonblocking().')
> > pexpect.TIMEOUT: Timeout exceeded in read_nonblocking().
>
> > Running the ssh command from the shell yields:
>
> > bash-2.05# ssh -q -l root myhost
> > root at myhost's password:
> > Last login: Wed Jan 16 17:10:32 2008 from x.x.x.x
> > Sun Microsystems Inc.   SunOS 5.9       Generic January 2003
> > Sun Microsystems Inc.   SunOS 5.9       Generic January 2003
> > root at myhost:/ #
>
> > I would be grateful if anyone could make a suggestion as to where I go
> > next?  Is read_nonblocking(), the correct method to be using here?
> > Are there any options inpxsshI need to explore (I've tried ssh -t,
> > but this means the password entry fails with raise ExceptionPxssh
> > ('password refused')).
>
> > Many thanks
>
> > Jon
>
> Did you get anywhere with this? I have the exact same problem on a
> CentOS Linux system.
>
> ---Kayvan

I don't know if anyone ever got back to you with a fix, but for me the
fix was really simple.

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

The reason is that you have to have stuff in the buffer in order to
read it.  In the case that they programmed for originally,
**something** exists in their prompt (probably a space) after the $ or
#.  In my case (and probably yours) the last thing on the prompt
**is** the $ or #, causing the buffer to be non-existent when the
first read_nonblocking() happens.  So all we do is put something there
before the read.

Why not just get rid of the first read since it is just "clearing the
buffer" anyway?  Because then, although it would now work for us, it
would no longer work for the original programmers.

 - Jinno



More information about the Python-list mailing list