google_utils.py 文件源码

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

项目:measure 作者: okfn 项目源码 文件源码
def get_authorized_http_object(scopes):
    '''JWT credentials authorization.

    :param scopes: the authorization scope to be requested
    :return: httplib2.Http object, with authorized credentials
    '''

    def _build_jwt_dict():
        jwt_dict = {key.replace(JWT_NAMESPACE, '').lower(): settings[key]
                    for key in settings
                    if key.startswith(JWT_NAMESPACE)}
        # Handle newlines in private key
        if 'private_key' in jwt_dict:
            jwt_dict['private_key'] = \
                jwt_dict['private_key'].replace('\\n', '\n')
        jwt_dict['PROJECT_ID'] = settings['GOOGLE_API_PROJECT_ID']
        return jwt_dict

    credentials = ServiceAccountCredentials.from_json_keyfile_dict(
        _build_jwt_dict(), scopes=scopes)
    return credentials.authorize(httplib2.Http())
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号