I am not much familiar with python. found this piece of code on "pexpect" example repo. I have made necessary changes. However, it is throwing "TypeError". Not able to figure out why.anybody can explain why and how can i fix this?
"pdb" was issuing error on "child = ssh_command(user, host, password)"
Error on pdb:
TypeError: "unsupported operand type(s) for +: 'float' and 'str'"
Code is give below,
import pexpect
def ssh_command(user, host, password):
new_sshkey = 'Are you sure you want to continue connecting'
child = pexpect.spawn('ssh %s@%s' %(user, host))
i = child.expect(new_sshkey, 'password: ')
if i == 0:
print 'ERROR.! SSH could not login.'
print child.before, child.after
if i == 1:
child.sendline('yes')
child.expect('password: ')
i = child.expect('password: ')
if i == 0:
print 'ERROR.! Permission Denied'
print child.before, child.after
return child
def main():
host = raw_input('Hostname: ')
user = raw_input('Username: ')
password = raw_input('Password: ')
child = ssh_command(user, host, password)
child.expect(pexpect.EOF)
print child.before
if __name__ == '__main__':
try:
main()
except Exception, e:
print str(e)
Most probably the error is caused by this line
i = child.expect(new_sshkey, 'password: ')
According to the documentation the expect
method is declared as follows
child.expect(pattern, timeout=-1, searchwindowsize=-1, async=False)
In your case you are passing 'password: '
as the second argument (timeout
) which
probably should be an int
.