我们从Python开源项目中,提取了以下5个代码示例,用于说明如何使用workflow.PasswordNotFound()。
def main(wf): should_reset = wf.args[0] if should_reset == 'True': # Remove stored google credentials remove_google_credentials() try: wf.delete_password('today.workflow.password') except PasswordNotFound: pass delete_keys = [] for value in wf.settings: if value in ['exchange_login', 'exchange_server', 'timezone', 'use_exchange', 'use_google'] or 'calendar' in value: delete_keys.append(value) for value in delete_keys: try: wf.logger.info("Deleting %s from settings", value) del wf.settings[value] except AttributeError: pass except KeyError: pass else: pass notify('Today Menu', 'Reset to defaults')
def exist_keychain(): email_in_data = wf.stored_data('duotai_email') if email_in_data == None: return False else: try: wf.get_password(email_in_data) except PasswordNotFound: return False return True
def is_authed(): expire_date = wf.stored_data(TOKEN_EXPIRES_IN) log.debug("expire_date: " + str(expire_date)) if (expire_date < time.time()): return False try: wf.get_password(TOKEN_KEY) return True except PasswordNotFound: return False
def login(wf, args): try: username = wf.get_password(USERNAME_KEY) password = wf.get_password(PASSWORD_KEY) except PasswordNotFound: notify( "Can't login", "You need to set your username and password before login", ) return 1 # Login code copied from # https://github.com/helloqiu/mianliao-login/blob/master/mianliao.py session = requests.Session() session.headers = ML_HEADERS session.verify = False # SB Mianliao if session.get(ML_URL).status_code != 200: notify( "Can't login", "Can not connect to the Mianliao Auth Server!", ) return 1 session.post( ML_URL, data='username=%s&password=%s&action=login' % (username, password), ) r = session.post(ML_URL, data={ 'ua': USERAGENT, 'sw': 1280, 'sh': 720, 'ww': 1280, 'wh': 720 }) wf.logger.debug(r.text) if u"?????????" in r.text: notify( "Can't login", "Mianliao Auth Server is down." ) return 1 if u"????" in r.text: notify( "Login Success!", ) return 0 notify( "Can't login", "Maybe wrong username or password?" )
def main(wf): #################################################################### # Get and Parse arguments #################################################################### # Build argument parser to parse script args and collect their values parser = argparse.ArgumentParser() # Check if the a force argument is parced and set the max_age parser.add_argument('--update', dest='update_method', nargs='?', default='normal') args = parser.parse_args(wf.args) wf.logger.info('update_method = ' + args.update_method) #################################################################### # Run argument-specific actions #################################################################### if args.update_method == 'force': max_age = 1 else: max_age = 600 #################################################################### # Get data the data from 10.000ft #################################################################### try: # Get API key from Keychain api_key = wf.get_password('10k_api_key') # Retrieve projects from cache if available and no more than 600 # seconds old def wrapper(): """`cached_data` can only take a bare callable (no args), so we need to wrap callables needing arguments in a function that needs none. """ return get_projects(api_key) # Get the new data projects = wf.cached_data('projects', wrapper, max_age=max_age) # Record our progress in the log file wf.logger.info('{} projects cached, max_age {} second(s)'.format( len(projects), max_age)) except PasswordNotFound: # API key has not yet been set # Nothing we can do about this, so just log it wf.logger.error('No API key saved')