Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/eclipse/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python getpass()在末尾追加回车符(在eclipse中)_Python_Eclipse_Getpasswd - Fatal编程技术网

Python getpass()在末尾追加回车符(在eclipse中)

Python getpass()在末尾追加回车符(在eclipse中),python,eclipse,getpasswd,Python,Eclipse,Getpasswd,当我在eclipse中运行以下代码时,getPass返回一个字符串,该字符串的末尾带有一个回车符 但是,当我在命令提示符下运行相同的代码时,它运行起来没有任何问题 import paramiko import getpass userPwd = getpass.getpass() print ('You have entered ',userPwd) ssh = paramiko.SSHClient() ssh.set_missing_host_key_policy(paramiko.Aut

当我在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):

输出(命令提示):

有人能解释这种含糊不清吗


谢谢

我怀疑eclipse设置为使用windows新行,即“\r\n”。您需要将其设置为使用UNIX新行(“\n”)

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


查看如何修改此选项。

我怀疑eclipse设置为使用windows新行,即“\r\n”。您需要将其设置为使用UNIX新行(“\n”)

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


查看如何修改此选项。

可能是eclipse shell添加了一个字符返回,而您的普通shell没有。但是当我用原始输入替换getPass()时,它工作得非常好。对于原始输入,为什么不在末尾添加额外的字符呢?可能是eclipse shell添加了一个字符返回,而您的普通shell没有。但是当我用原始输入替换getPass()时,它工作得非常好。如果是原始输入,为什么不在末尾添加额外字符?
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')