Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'spawn' object has no attribute 'pexpect' #511

Open
repoyxj opened this issue Jul 2, 2018 · 1 comment
Open

'spawn' object has no attribute 'pexpect' #511

repoyxj opened this issue Jul 2, 2018 · 1 comment

Comments

@repoyxj
Copy link

repoyxj commented Jul 2, 2018

centos 7.2
python 2.7
/usr/lib/python2.7/site-packages/pexpect
pexpect 4.6.0

test.py

#!/usr/bin/python

import pexpect

def send_comm(child, cmd):
child.sendline(cmd)
child.expect(Promt)

def connect(user, host, password):
connStr = 'ssh ' + user + '@' + host
child = pexpect.spawn(connStr)
result = child.pexpect([pexpect.TIMEOUT, 'password:'])
if result == 0:
print "[-] Error"
return
elif result == 1:
child.sendline(password)
child.expect(Promt)
return child

def main():
host = '192.168.xx.xx'
user = 'root'
password = '*************'
child = connect(user,host,password)
send_command(child, 'w')

if name == 'main':
main()
######### issue problem ###
Traceback (most recent call last):
File "ss.py", line 30, in
main()
File "ss.py", line 26, in main
child = connect(user,host,password)
File "ss.py", line 13, in connect
result = child.pexpect([pexpect.TIMEOUT, 'password:'])
AttributeError: 'spawn' object has no attribute 'pexpect'

any ideas ? thinks

@jnatschev
Copy link

jnatschev commented Jul 2, 2018 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants