pxssh error 'could not synchronize with original prompt'

python-3.x

Solution

I have solved it by adding sync_multiplier argument to the login function.

s.login(hostname, username, password, sync_multiplier=5 auto_prompt_reset=False)

note that sync_multiplier is a communication timeout argument to perform successful synchronization. it tries to read prompt for at least sync_multiplier seconds. Worst case performance for this method is sync_multiplier * 3 seconds.

I personally set sync_multiplier=2 but it depends on the communication speed on the system I work on.

Problem

I have been getting the below error while using pxssh to get into remote servers to run unix commands ( like uptime ) ``` Traceback (most recent call last): ``` File "./ssh_pxssh.py", line 33, in login_remote(hostname, username, password) File "./ssh_pxssh.py", line 12, in login_remote if not s.login(hostname, username, password): File "/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/pexpect/pxssh.py", line 278, in login ``` **raise ExceptionPxssh ('could not synchronize with original prompt') ``` pexpect.pxssh.ExceptionPxssh: could not synchronize with original prompt** Line 33 is where I call this function in main. The function I am using is here : ``` def login_remote(hostname, username, password): s = pxssh.pxssh() s.force_password = True if not s.login(hostname, username, password, auto_prompt_reset=False): print("ssh to host :"+ host + " failed") print(str(s)) else: print("SSH to remote host " + hostname + " successfull") s.sendline('uptime') s.prompt() print(s.before) s.logout() ``` The error does not come each time I run the script. Rather it is intermittent. It comes 7 out of 10 times I run my script.

Original source