How to use the Python getpass.getpass in PyCharm

前端 未结 6 1123
醉话见心
醉话见心 2020-12-08 14:17

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

相关标签:
6条回答
  • 2020-12-08 14:48

    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:")
    
    0 讨论(0)
  • 2020-12-08 14:49

    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.

    0 讨论(0)
  • 2020-12-08 14:49

    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

    0 讨论(0)
  • 2020-12-08 14:53

    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.

    0 讨论(0)
  • 2020-12-08 14:55

    For PyCharm 2018.3

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

    0 讨论(0)
  • 2020-12-08 14:57

    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)
    
    0 讨论(0)
提交回复
热议问题