Oliver Blue
Oliver Blue

Reputation: 707

Cannot import name 'spawn' for pexpect while using pxssh

This is the code I am trying to run:

from pexpect import pxssh
s = pxssh.pxssh()
if not s.login ('myip', 'myusername', 'mypassword'):
    print ("SSH session failed on login.")
    print (str(s))
else:
    print ("SSH session login successful")
    s.sendline ('ls -l')
    s.prompt()         # match the prompt
    print (s.before)     # print everything before the prompt.
    s.logout()

This is the error I am getting on running that code:

Traceback (most recent call last):
  File "test_pexpect.py", line 1, in <module>
    from pexpect import pxssh
  File "C:\Python35\lib\site-packages\pexpect\pxssh.py", line 23, in <module>
    from pexpect import ExceptionPexpect, TIMEOUT, EOF, spawn
ImportError: cannot import name 'spawn'

Can anyone help me out? I am using python3.5 on Windows

Upvotes: 15

Views: 17965

Answers (2)

stefan.stt
stefan.stt

Reputation: 2627

pxssh is not currently supported on Windows.

You can read more about it on https://github.com/pexpect/pexpect/issues/339:

pxssh is not currently supported on Windows, as it uses a pty.

Upvotes: 11

shilpa-bo
shilpa-bo

Reputation: 1

Pexpect is not supported on Windows as mentioned in the other answer. But, wexpect (a Windows port of pexpect) is.

You can do:

import wexpect 

s = wexpect.spawn('ssh username@hostname')

You can use a try-except with a timeout to catch the case where SSH session fails on login.

Upvotes: 0

Related Questions