-1

This is my code:

import pexpect
import spawn

host = 'xx.xx.xx.xx'
userName = 'akshay'
password = 'xxxxxxxxxxxxxx'

**child = spawn('ssh %s@%s' %(userName, host))**
child.setwinsize(1000,200)
child.expect(['password'], timeout=5)

Here I'm trying to SSH into a box using pexpect and spawn but my Pycharm always returns

TypeError: 'module' object is not callable in the bold line

dstrants
  • 7,423
  • 2
  • 19
  • 27

1 Answers1

0

You are doing it completely wrong, first of all spawn is not a module that you need to import

Here is the code :

import pexpect

host = 'xx.xx.xx.xx'
userName = 'akshay'
password = 'xxxxxxxxxxxxxx'

child = pexpect.spawn('command here',timeout=5)
child.setwinsize(1000,200)
child.expect('password')

Always define timeout in pexpect.spawn, becuase you cannot override it anywhere else

dheeraj tripathi
  • 345
  • 4
  • 14