Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python getpass.getpass() function call hangs

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
like image 710
jlcv Avatar asked Jul 03 '14 03:07

jlcv


People also ask

What does Getpass do 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: “.

Is Getpass standard Python library?

The getpass module is part of the Python Standard Library, filed under the 'Generic Operating System Services' category.


2 Answers

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.

like image 81
edi Avatar answered Sep 22 '22 20:09

edi


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.

like image 36
jlcv Avatar answered Sep 21 '22 20:09

jlcv