Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

getPass() echoing password in Eclipse

Hey all just started dabbling in a little Python to help out with a few scripts at work, but I seem to be getting hung up on a little issue.

I am using Eclipse with pydev for my development platform and developing against python 2.7.3. I am just trying to prompt a user for their password, using:

password = getpass.getpass()

That line works as expected when running in the terminal/command prompt, however when I am running in the Eclipse console, the user's input isn't hidden like it should be. Any ideas how to fix this?

like image 711
Brent Hronik Avatar asked Mar 27 '13 20:03

Brent Hronik


People also ask

How do I use Getpass?

The getpass() function is used to prompt to users using the string prompt and reads the input from the user as Password. The input read defaults to “Password: ” is returned to the caller as a string. Here, no prompt is provided by the caller. So, it is set to the default prompt “Password”.

What is Getpass?

The getpass module provides two functions: getpass. getpass(prompt='Password: ', stream=None) Prompt the user for a password without echoing. The user is prompted using the string prompt, which defaults to 'Password: ' .

What is the Getpass module in Python?

The getpass module provides a platform-independent way to enter a password in a command-line program, as Example 2-25 shows. getpass(prompt) prints the prompt string, switches off keyboard echo, and reads a password. If the prompt argument is omitted, it prints " Password: “.


1 Answers

This is documented behaviour - some terminals are not capable of echo-free input, in that case, it should give a warning instead:

If echo free input is unavailable getpass() falls back to printing a warning message to stream and reading from sys.stdin and issuing a GetPassWarning.

From the docs for getpass.getpass().

like image 158
Gareth Latty Avatar answered Sep 21 '22 20:09

Gareth Latty