Giter Site home page Giter Site logo

Comments (14)

jquast avatar jquast commented on September 26, 2024

I will look into this -- but considering you're probably in a jam, I encourage using the 'paramikko' python module, which gives full ssh environment and code control in python, instead of just driving whatever command-line ssh client is provided with your OS.

Much of paramikko deprecates the need for pxssh & examples of this library. It's also a pretty nice API.

from pexpect.

jquast avatar jquast commented on September 26, 2024

Also please see the comment in sync_original_prompt of pxssh.py, which is the fail

        '''This attempts to find the prompt. Basically, press enter and record
        the response; press enter again and record the response; if the two
        responses are similar then assume we are at the original prompt. This
        is a slow function. It can take over 10 seconds. '''

Is it possible that the prompt of your remote server may change, within a few seconds? This would be especially true if any of the hour:minute:second is somewhere in a fancy PS1 variable.

You might try to set PS1='$ ' on your remote machine temporarily to see if it solves the problem.

from pexpect.

jquast avatar jquast commented on September 26, 2024

I have not been able to reproduce this, the example works fine for me, I'll need more details.

Looking at pexpect/pxssh.py's pxpect.login() method, the following seem relevant questions for reproduction:

  1. do you use an ssh key? does that ssh key have a passphrase?
  2. what is the local OS and remote OS?
  3. what is the remote shell? how does it look when you ssh manually, rather normal? or confusing '--More--' prompts or some such?
  4. Could you add 'print(self.before)' to pexpect/pxssh.py just before raise ExceptionPxssh ('could not synchronize with original prompt') and report? I wonder what is in the 'buffer' that is not matching, here.

this module is definitely messy, I'm not surprised there are problems here !

from pexpect.

jquast avatar jquast commented on September 26, 2024

could not reproduce !

from pexpect.

csullivan avatar csullivan commented on September 26, 2024

Today received this same error on Debian Wheezy >>

'File "/usr/lib/python2.7/dist-packages/pxssh.py", line 249, in login
raise ExceptionPxssh ('could not synchronize with original prompt')
pxssh.ExceptionPxssh: could not synchronize with original prompt'

  1. Not using an ssh key
  2. local and remote OS are identical as I am sshing on site controlled intra network.
  3. see 2
  4. 'None'

from pexpect.

jquast avatar jquast commented on September 26, 2024

Hi @csullivan, I have two Debian Wheezy's as well, so we can definitely work this out. Thank you.

  1. please specify: what is your shell? For me, it is /bin/bassh
$ grep $UID /etc/passwd
jquast:x:1000:100::/home/jquast:/bin/bash

In the mean time --

  • I'll come up with a script of some kind, run it between my own two debians.
  • I will modify it for providing debugging information to help identify the issue.
  • you will set appropriate user/password and run it
  • you will censor out any sensitive information from output,
  • you will share that with me (or maybe the issue will be obvious to you?)

from pexpect.

jquast avatar jquast commented on September 26, 2024

@csullivan, please use this script: https://gist.github.com/jquast/9636451

It simply hooks into a few places of pxssh class with new class, Debug_PXSSH.

It prompts to login to the target server and execute uptime command.

It will help understand what the final two prompts for comparison it evaluates to be "less than 40% different" or some such arbitrary equation is used. I would like to see them, myself. Perhaps it will be obvious to you with the debug output, but if not, you may email it to [email protected] rather than this public issue, or simply censor anything you don't want to share.

Here is my own session for comparison:

$ /tmp/test-pxssh.py
hostname: ns1
username [dingo1]: dingo
port [22]: 1984
password:

[sync_original_prompt]
[sendline::input='']
[try_read_prompt::prompt='\x1b]0;dingo@ns1: ~\x07dingo@ns1:~$ ']
[sendline::input='']
[try_read_prompt::prompt='\r\n\x1b]0;dingo@ns1: ~\x07dingo@ns1:~$ ']
[sendline::input='']
[try_read_prompt::prompt='\r\n\x1b]0;dingo@ns1: ~\x07dingo@ns1:~$ ']
[sendline::input='']
[try_read_prompt::prompt='\r\n\x1b]0;dingo@ns1: ~\x07dingo@ns1:~$ ']
[val=0.0, ld=0, len_a=32]

[sendline::input='unset PROMPT_COMMAND']
[sendline::input="PS1='[PEXPECT]\\$ '"]
[sendline::input='uptime']
[session.before='uptime\r\n 06:26:17 up 109 days, 10:55,  2 users,  load average: 0.10, 0.05, 0.01\r\n']
[sendline::input='exit']

from pexpect.

jquast avatar jquast commented on September 26, 2024

If anybody has this issue, try the script, https://gist.github.com/jquast/9636451 which may provide you with the cause of this failure. And if you could suggest how to make this failure more clear, please do!

from pexpect.

axper avatar axper commented on September 26, 2024

I can successfully use ssh command to log into remote debian, but pxssh fails with this message. Here is the output of your script.

hostname: 192.168.56.104
username [----]: user 
port [22]: 
password: 
Traceback (most recent call last):
  File "./pxssh-test.py", line 63, in <module>
    session.login(hostname, username, password, port=1984)
  File "/usr/lib/python2.7/site-packages/pexpect/pxssh.py", line 264, in login
    i = self.expect(["(?i)are you sure you want to continue connecting", original_prompt, "(?i)(?:password)|(?:passphrase for key)", "(?i)permission denied", "(?i)terminal type", TIMEOUT, "(?i)connection closed by remote host"], timeout=login_timeout)
  File "/usr/lib/python2.7/site-packages/pexpect/__init__.py", line 1451, in expect
    timeout, searchwindowsize)
  File "/usr/lib/python2.7/site-packages/pexpect/__init__.py", line 1466, in expect_list
    timeout, searchwindowsize)
  File "/usr/lib/python2.7/site-packages/pexpect/__init__.py", line 1554, in expect_loop
    raise EOF(str(err) + '\n' + str(self))
pexpect.EOF: End Of File (EOF). Exception style platform.
<__main__.Debug_PXSSH object at 0x7f0c8b3b1fd0>
version: 3.3
command: /usr/bin/ssh
args: ['/usr/bin/ssh', '-q', '-p', '1984', '-l', 'user', '192.168.56.104']
searcher: <pexpect.searcher_re object at 0x7f0c8b347090>
buffer (last 100 chars): ''
before (last 100 chars): ''
after: <class 'pexpect.EOF'>
match: None
match_index: None
exitstatus: None
flag_eof: True
pid: 11108
child_fd: 3
closed: False
timeout: 30
delimiter: <class 'pexpect.EOF'>
logfile: None
logfile_read: None
logfile_send: None
maxread: 2000
ignorecase: False
searchwindowsize: None
delaybeforesend: 0.05
delayafterclose: 0.1
delayafterterminate: 0.1

from pexpect.

jquast avatar jquast commented on September 26, 2024

Thanks @axper. I will update the test script to add '-v' option to the ssh command if you could try that for me.

It looks like /usr/bin/ssh exited or the remote end disconnected on you before any commands could be processed. interesting. Hopefully '-v' for ssh will provide some explanation.

from pexpect.

tcpayne avatar tcpayne commented on September 26, 2024

Thanks @jquast for the test script - really helped me out today.

You've probably figured this out by now, but I think the problem @axepr may have had is that, although the script asks for a port number, I it's hard coded to use port '1984'.

cheers

from pexpect.

pBogey avatar pBogey commented on September 26, 2024

Hello, for anyone having this issue and ending up here, I just want to share some insight from my recent troubles with this issue. I am using pxssh in some scripts for testing some embedded system running linux. Anyway, I was able to connect through ssh manually from a terminal and everything was great, prompt was as expected and all. Using this script from @jquast it was failing:

[sync_original_prompt]
[sendline::input='']
[try_read_prompt::prompt=b'']
[sendline::input='']
[try_read_prompt::prompt=b'']
[sendline::input='']
[try_read_prompt::prompt=b'']
[sendline::input='']
[try_read_prompt::prompt=b'']

So that was weird. Seems like the prompt was empty, but it was actually ok when connecting manually. Anyway, I have just reflashed the sdcard and the script was now working. I have no idea why, but maybe it helps someone struggling to figure it out. The sdcard was working well apparently, everything seemed ok, except this error with SSH.

from pexpect.

jquast avatar jquast commented on September 26, 2024

Thanks, I can only suggest, maybe because it is embedded that the prompt could have been slow? This debug script has 1-second timeouts, I would suggest increasing the timeouts if it happens again, thanks for the report

from pexpect.

pBogey avatar pBogey commented on September 26, 2024

You're actually right, it seems it has nothing to do with the sdcard. Or who knows...? So after my initial message, the board was functioning well in CI environment and today it started to fail again when connecting through SSH. So I was thinking sdcard broke again. Anyway, I'm not in the office to replace it so I thought I would play again with your script a little and it seems the timeout has something to do with it.

Ran your script in a loop and these are my results:

syn_multipler of 5s:
1: OK
2: FAIL
3: FAIL
4: OK
5: FAIL
6: FAIL
7: OK
8: FAIL
9: FAIL
10: OK

syn_multiplier of 10s:
1: OK
2: OK
3: OK
4: OK
5: OK
6: OK
7: OK
8: OK
9: OK
10: OK

from pexpect.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.