manjunath K.R
manjunath K.R

Reputation: 13

cannot import name 'spawn' from 'pexpect' on windows

Trying to ssh tunnel from Windows system through linux jumphost with ip (xx.xx.xx.xx) and connect to target config windows system with ip 127.0.0.1

import sys import paramiko import subprocess import pexpect from pexpect.popen_spawn import PopenSpawn import winpexpect from winpexpect.winspawn import winspawn

child = winpexpect.winspawn('ssh -L 22:xx.xx.xx.xx:4022 [email protected] -o StrictHostKeyChecking=no') child.expect('127.0.0.1') child.sendline('password')

The above program throws below error when run on Windows system. File "C:\Python38\lib\site-packages\winpexpect.py", line 18, in from pexpect import spawn, ExceptionPexpect, EOF, TIMEOUT ImportError: cannot import name 'spawn' from 'pexpect' (C:\Python38\lib\site-packages\pexpect_init_.py)

Upvotes: 0

Views: 1012

Answers (1)

user20276239
user20276239

Reputation: 1

cannot import name 'spawn' from 'pexpect' spawn is not for Windows system. use pexpect.popen_spawn.PopenSpawn for windows. check here https://pexpect.readthedocs.io/en/stable/overview.html#pexpect-on-windows

Upvotes: 0

Related Questions