Created
May 26, 2014 19:00
-
-
Save gentoo90/5ae7c899f81942513d26 to your computer and use it in GitHub Desktop.
Ask password if not found in keyring
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from getpass import getpass | |
try: | |
import keyring | |
def get_passwd(address, username): | |
passwd = keyring.get_password(address, username) | |
if passwd is None: | |
passwd = getpass('Password for %s: ' % address) | |
keyring.set_password(address, username, passwd) | |
return passwd | |
except ImportError: | |
def get_passwd(address, username): | |
return getpass('Password for %s: ' % address) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment