10
votes

When I run this code:

import getpass

p = getpass.getpass(prompt='digite a senha\n')
if p == '12345':
    print('YO Paul')
else:
    print('BRHHH')
print('O seu input foi:', p) # p = seu input

I got this warning:

Warning (from warnings module):
   File "/usr/lib/python3.4/getpass.py", line 63
    passwd = fallback_getpass(prompt, stream)
GetPassWarning: Can not control echo on the terminal. Warning: Password input may be echoed.
4
That would be system and terminal-dependent: docs.python.org/2/library/getpass.html Prompt the user for a password without echoing. ... 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. - handle
I think the warning is telling you precisely that there is not a way (that Python knows or recognizes) to prevent the password from being echoed on the system where the message is emitted. - John Bollinger
I am using IDLE: Python 3.4.3 (default, Oct 14 2015, 20:28:29) [GCC 4.8.4] on linux - Paul Sigonoso
IDLE interferes with normal console input & output; getpass was not designed to be used in such environments. - PM 2Ring

4 Answers

11
votes

Use an actual terminal -- that is, an environment where stdin, stdout and stderr are connected to /dev/tty, or another PTY-compliant device.

The IDLE REPL does not meet this requirement.

4
votes

Run your code in terminal, instead of the IDE. you will see that there is no more warning there. To run your code, enter this command in terminal:

python3 your_program.py
2
votes

Rather than deal with changing the current working directory in a terminal that has not started Python (which would mean you type something like python3 script.py--and it will fail unless the current working directory is already specified), start Python in your terminal and run this one-line command:

exec(open('C:\folder\script.py').read())

where you change the path string 'C:\folder\script.py' to match wherever your file is located on disk (the string does need to be specified with quotes).

1
votes

use cmd ie. command prompt and then run the file in it.

like:

python abc.py