pxssh throwing End Of File (EOF). Exception style platform exception

若如初见. 提交于 2019-12-02 04:42:55

问题


I am having problem using pxssh module. My code is below:

    try:
        ssh_handle = pxssh.pxssh(timeout=None)
        ssh_handle.logfile = sys.stdout
        ssh_handle.login(host, username, password)
        index = ssh_handle.expect(['Are you sure you want to continue connecting \(yes\/no\)\? ', '.*?password:.*', '.*?\$.*'])
        if index == 0:
            ssh_handle.sendline('yes')
            ssh_handle.sendline(password)
        if index == 1:
            ssh_handle.sendline(password)
        ssh_handle.sendline('sudo -s')
        ssh_handle.sendline(password)
        return ssh_handle
    except pxssh.ExceptionPxssh as e:
        print "SSH connection to %s failed" % host
        sys.exit()

For some reason I keep getting the error:

File "/usr/lib/python2.7/dist-packages/pexpect/pxssh.py", line 313, in login
    if not self.sync_original_prompt(sync_multiplier):
  File "/usr/lib/python2.7/dist-packages/pexpect/pxssh.py", line 205, in sync_original_prompt
    b = self.try_read_prompt(sync_multiplier)
  File "/usr/lib/python2.7/dist-packages/pexpect/pxssh.py", line 168, in try_read_prompt
    prompt += self.read_nonblocking(size=1, timeout=timeout)
  File "/usr/lib/python2.7/dist-packages/pexpect/__init__.py", line 919, in read_nonblocking
    raise EOF('End Of File (EOF). Exception style platform.')
pexpect.EOF: End Of File (EOF). Exception style platform.

I am not sure what I am doing wrong and would appreciate any pointers anyone might have.

Thanks in advance, nav


回答1:


You can either do ssh_handle.expect(pexpect.EOF) and read the result in ssh_handle.before. Or try to remove the '\' from '(yes/no)\?' (i.e. do '(yes/no)?'). The last suggestion worked for me on Suse.

Link: http://pexpect.sourceforge.net/doc/



来源:https://stackoverflow.com/questions/24919980/pxssh-throwing-end-of-file-eof-exception-style-platform-exception

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!