【发布时间】:2016-05-21 12:28:55
【问题描述】:
当我在 eclipse 中运行以下代码时,getPass 返回一个以回车符结尾的字符串。
但是,当我在命令提示符下运行相同的代码时,它运行没有任何问题。
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)
输出(Eclipse):
Warning: Password input may be echoed.
Password: Mypassword@123
('You have entered ', 'Mypassword@123\r')
输出(命令提示符):
Warning: Password input may be echoed.
Password: Mypassword@123
('You have entered ', 'Mypassword@123')
谁能解释这种含糊不清的地方?
谢谢!!
【问题讨论】:
-
可能是 eclipse shell 添加了字符返回,而您的普通 shell 没有。
-
但是当我用 raw_input 替换 getPass() 时,它工作得很好。为什么在 raw_input 的情况下不在末尾添加额外的字符?