I want to use:
import getpass
password = getpass.getpass("Enter your password:")
print password
On winx64 using python 2.7... The 2nd line hangs. I dont see the dialog. " Enter your password:"
I will need the config function found in the ‘decouple’ module in python to hide the password. To install this module, run the following command on your terminal: After this gets installed, make a .env file in the same folder as our test.py file, and copy-paste the userID and password in that file, like this,
"Password: " (with a space after the colon) is the default prompt, so there's often no need to specify it in the call to getpass.getpass (). this gave me an error Warning (from warnings module): File "C:\Python27\lib\getpass.py", line 92 return fallback_getpass (prompt, stream) GetPassWarning: Can not control echo on the terminal.
Getting user input with Python is pretty easy. You make a call to input, and whatever the user types is stored as a variable: My problem was when I typed a password into the terminal in response to my password prompt, everything I typed was visible to anyone looking over my shoulder or scrolling through my terminal history:
In order to make applications more secure and make these secrets hidden from everyone, it's also better to use the secrets as an environment variable or config file. In Python, there are various packages that can be used for this like: python-decouple , python-dotenv , jproperties. Let's deep dive into each of them to understand the flow and usage.
According to your comment above, you are actually using ipython within spyder. The only issue I came across for getpass in Spyder is at their Google code page. The issues is not exactly the same as yours, but included in the comments is the following code snippet:
def spyder_getpass(prompt='Password: '):
set_spyder_echo(False)
password = raw_input(prompt)
set_spyder_echo(True)
return password
Try using the method above (utilizing raw_input instead of getpass) to get the required password you need.
As the other comments already indicated, you have to run this script within the Power Shell to actually see the "Enter your password:"
text and be able to enter a password.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With