__init__.py 文件源码

python
阅读 20 收藏 0 点赞 0 评论 0

项目:oauth2l 作者: google 项目源码 文件源码
def _GetCredentialsVia3LO(client_info, credentials_filename=None):
    credential_store = _GetCredentialStore(credentials_filename,
                                           client_info['client_id'],
                                           client_info['scope'])
    credentials = credential_store.get()
    if credentials is None or credentials.invalid:
        for _ in range(10):
            # If authorization fails, we want to retry, rather
            # than let this cascade up and get caught elsewhere.
            # If users want out of the retry loop, they can ^C.
            try:
                flow = client.OAuth2WebServerFlow(**client_info)
                flags, _ = tools.argparser.parse_known_args(
                    ['--noauth_local_webserver'])
                credentials = tools.run_flow(
                    flow, credential_store, flags)
                break
            except (SystemExit, client.FlowExchangeError) as e:
                # Here SystemExit is "no credential at all", and the
                # FlowExchangeError is "invalid" -- usually because
                # you reused a token.
                pass
            except httplib2.HttpLib2Error as e:
                raise ValueError(
                    'Communication error creating credentials:'
                    '{}'.format(e))
        else:
            credentials = None
    return credentials
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号