Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use the Python getpass.getpass in PyCharm

Tags:

python

pycharm

I have found getpass does not work in PyCharm. It just hangs.

In fact is seems msvcrt.getch and raw_input also don't work, so perhaps the issue is not with getpass. Instead with the 'i' bit of PyCharm's stdio handling.

The problem is, I can't put my personal password into code as it would end up in SVN which would be visible to other people. So I use getpass to get my password each time.

On searching, all I can find is that "Pycharm does dome hacking to get Django working with getpass" but no hint as to what that hack is....

I've looked at getpass and it uses msvcrt on Windows (so this problem might only be on Windows)

My question is: Is there a workround for this issue?

like image 540
Jason M Avatar asked Feb 18 '15 08:02

Jason M


People also ask

What is Getpass library 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: “.

How does Python handle password prompt?

getpass() and getuser() in Python (Password without echo) getpass() prompts the user for a password without echoing. The getpass module provides a secure way to handle the password prompts where programs interact with the users via the terminal.

Is Getpass standard Python library?

There are two functions defined in getpass module of Python's standard library. They are useful whenever a terminal based application needs to be executed only after validating user credentials.


2 Answers

For PyCharm 2018.3

Go to 'Edit Configurations' and then select 'Emulate terminal in output console'.

like image 183
Abhyudaya Sharma Avatar answered Sep 29 '22 05:09

Abhyudaya Sharma


I've run into this running Pycharm CE 4.5 on Windows. The workaround I use is to run your program in debug mode, then you get a console tab where you can enter your password when using getpass.

like image 36
Mark M Avatar answered Sep 29 '22 07:09

Mark M