Skip to content

Instantly share code, notes, and snippets.

@gentoo90
Created May 26, 2014 19:00
Show Gist options
  • Save gentoo90/5ae7c899f81942513d26 to your computer and use it in GitHub Desktop.
Save gentoo90/5ae7c899f81942513d26 to your computer and use it in GitHub Desktop.
Ask password if not found in keyring
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