I am trying to get a prompt that will ask for my password but when I try to call getpass.getpass()
it just freezes. I am running on Windows 7 64 bit using Python 2.7 on Canopy.
import sys
import getpass
p = getpass.getpass()
print p
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: “.
The getpass module is part of the Python Standard Library, filed under the 'Generic Operating System Services' category.
It is correct that Python "effectively freezes because it can't receive the input from standard input", however, for windows you can prefix your command with winpty
. Then password can be inputted correctly when started like:
winpty python fileToExecute.py
winpty provides a interface similar to a Unix pty-master in a way that communication is also possible from windows terminals.
Python "effectively freezes because it can't receive the input from standard input". See https://support.enthought.com/entries/22157050-Canopy-Python-prompt-QtConsole-Can-t-run-getpass-or-interactive-OS-shell-commands-or-Windows-process
The fix is to use a different interpreter. I switched to IDLE and fixed the issue.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With