How to use the Python getpass.getpass in PyCharm

21,451

Solution 1

For PyCharm 2018.3

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

Solution 2

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.

Solution 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'

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)

Solution 4

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.

Solution 5

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:")
Share:
21,451
Jay M
Author by

Jay M

I've been an electronics and computer geek from a very young age. I currently work as a hardware design engineer. I am very experienced in electronics and VHDL as well as programing in several languages such as Python, C, C++ (to name a few) as well as various assembly languages. In my spare time I like to ride fast bikes, play guitar and SCUBA dive. I'm a huge fan of the Open Source Software movement

Updated on August 28, 2020

Comments

  • Jay M
    Jay M almost 4 years

    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?