35

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?

Jay M
  • 3,736
  • 1
  • 24
  • 33

6 Answers6

36

For PyCharm 2018.3

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

Abhyudaya Sharma
  • 1,173
  • 12
  • 18
6

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.

Mark M
  • 61
  • 1
  • 2
2

A common solution to this would be to store the credentials in a file which you mark ignored by your VCS. Then just:

with open('credentials.txt') as f:
    user, pw = f.read().split('\n')  # or similar

Alternatively, have them specified in environment variables. Both of these methods should work around PyCharm's handling of stdin.

nelfin
  • 1,019
  • 7
  • 14
2

At first use, my code in pycharm and then click the "Run" then click the "Edit Configurations" then select the 'Emulate terminal in output console'

from selenium import webdriver
from getpass import getpass
email=input("Enter the email:")
password= getpass("Enter the password:")
driver=webdriver.Chrome()
url='https://www.facebook.com/'
driver.get(url)
user_id=driver.find_element_by_id("email")
user_id.send_keys(email)
user_password=driver.find_element_by_id("pass")
user_password.send_keys(password)
login_button = 
driver.find_element_by_id("u_0_b").click()
time.sleep(30)
Sayandip Dutta
  • 15,602
  • 4
  • 23
  • 52
Pabel Huq
  • 21
  • 3
  • At first use, my code in pycharm and then click the "Run" then click the "Edit Configurations" then select the 'Emulate terminal in output console' – Pabel Huq Jul 31 '20 at 21:16
1

Unfortunately, getpass() tends to fail miserably (I tested it with IDLE and PyScripter without any success on Python 3.4). I would suggest using passwordbox from easygui - it works wonderfully provided you do not use ver. 0.98 (something is messed up there), it is safe to use ver. 0.96.

Download easygui ver. 0.96, unpack it to a temporary folder, and from that folder install it with:

python setup.py install

and use passwordbox in your program:

from easygui import passwordbox
password = passwordbox("PASSWORD:")
sattik
  • 71
  • 4
1

In my case, even after setting the configuration to "Emulate terminal in output console" getpass.getpass() didn't work. To solve the problem, "I set the configuration to Run With Python Console" Editing the configuration

But there was a different problem now: The console was echoing the password in the python console. If you don't want that to happen, I recommend you to run the program using cmd or Linux terminal. The output in Linux terminal looked like this: Output in Terminal

Strider
  • 11
  • 1