【问题标题】:getpass() appending carriage return at the end (in eclipse)getpass() 在末尾附加回车(在 Eclipse 中)
【发布时间】: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 的情况下不在末尾添加额外的字符?

标签: python eclipse getpasswd


【解决方案1】:

我怀疑 Eclipse 设置为使用 Windows 换行符,即“\r\n”。您需要将其设置为使用 UNIX 新行 ('\n')

基本上,这意味着 python 方法 'getpass()' 正在截断缓冲区中的最后一个字符。由于您要给出两个字符,因此缺少 \r。

Look here 看看如何修改这个选项。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-03-18
    • 1970-01-01
    • 1970-01-01
    • 2016-11-10
    • 2013-04-16
    • 2012-06-20
    • 2018-12-17
    • 1970-01-01
    相关资源
    最近更新 更多