getpass() appending carriage return at the end (in eclipse)

673 views Asked by At

When I run the following code in eclipse, getPass returns a string suffixed with a carriage at the end.

However, when I run the same code in command prompt it runs without any problem.

import paramiko
import getpass

userPwd = getpass.getpass()
print ('You have entered ',userPwd)

ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect('ese.rnd.sanl.se', username='abc', 
    password=userPwd)
stdin,stdout,stderr=ssh.exec_command("ls")
data1=stdout.read().splitlines();

for line in data1:
    print (line)

Output (Eclipse):

Warning: Password input may be echoed.
Password: Mypassword@123
('You have entered ', 'Mypassword@123\r')

Output (Command Prompt):

Warning: Password input may be echoed.
Password: Mypassword@123
('You have entered ', 'Mypassword@123')

Can anyone explain this ambiguity?

Thanks!!

1

There are 1 answers

0
DGuimar On

I suspect eclipse is set to use windows newline i.e. '\r\n'. You will want to set it to use the UNIX new line ('\n')

Basically, this means that the python method 'getpass()' is chopping the final character in the buffer. Since you are giving two characters, it is missing the \r.

Look here to see how to modify this option.