2

How to prevent echo from input ??

Have tried "getpass()" but no luck.

On Windows IDLE, it doesn't work

    Python 3.3.2 (v3.3.2:d047928ae3f6, May 16 2013, 00:03:43) [MSC v.1600 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> import getpass
>>> p = getpass.getpass(prompt="Input: ")
Warning: Password input may be echoed.
Input: abc <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< It still echos..

On the terminal of the Windows, it works

Python 3.3.2 (v3.3.2:d047928ae3f6, May 16 2013, 00:03:43) [MSC v.1600 32 bit (In
tel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import getpass
>>> p = getpass.getpass(prompt="Input: ")
Input:
>>>

Is there a easy way to prevent echo from input ?

5
  • 3
    How are Windows and terminal on Windows different?
    – squiguy
    Jul 8, 2013 at 6:27
  • 2
    I believe one is IDLE, and other is Terminal. Jul 8, 2013 at 6:27
  • I think the question needs some clarification, if it's IDLE, it should probably at least be mentioned in the question. Jul 8, 2013 at 6:29
  • Yes, the first one is in the Shell that starts from IDLE, and the second one is in the Shell that starts from command line. Both of them are all in the same computer, and I thought they are the same python shell.
    – Cray Kao
    Jul 8, 2013 at 8:35
  • I gave up.... No easy workaround to get input without echo on the Python 3.3.x. and the IDLE shell. Can't believe, but it DOES !! :-(
    – Cray Kao
    Jul 8, 2013 at 14:36

1 Answer 1

3

I'm assuming your first example there is in IDLE.

From getpass.win_getpass():

if sys.stdin is not sys.__stdin__:
    return fallback_getpass(prompt, stream)

IDLE replaces sys.stdin with a different object. getpass detects that somebody has wrapped stdin and fails for security reasons.

See: http://bugs.python.org/issue9290

3
  • win_getpass use the function of getch(), but it can't work on the IDLE env. So that the echo can't be turn off on the IDLE.
    – Cray Kao
    Jul 8, 2013 at 14:41
  • 2
    IDLE is a development environment. The workaround is not to run secure apps in IDLE in production. I mean, anybody who could read the local echo could break into the interpreter and go through the variables in the module until they find the password!
    – llb
    Jul 8, 2013 at 14:44
  • 1
    I know IDEL is a development environment. But, if the program can't work in the DEV, how we will know if it will work in PRD !! It's the problem!! If the development environment can act as the production env, it will be easier for development, doesn't it. WHAT WE GET IS WHAT WE GET NO MATTER IT IS DEV or PRD If so, then it will be more easier for development.
    – Cray Kao
    Jul 8, 2013 at 15:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.