首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >函数service_account.Credentials.from_service_account_info()不工作

函数service_account.Credentials.from_service_account_info()不工作
EN

Stack Overflow用户
提问于 2020-05-18 16:40:19
回答 1查看 2.2K关注 0票数 0

我正在编写一个基于GCP服务的应用程序,我需要访问一个外部项目。我将我需要访问的另一个项目的身份验证文件的信息存储在Firestore数据库中。我读了这份文件并尝试应用它,但我的代码不起作用。正如文档所述,我传递给身份验证方法的是dictionarystr,str。这是我的密码:

代码语言:javascript
复制
from googleapiclient import discovery
from google.oauth2 import service_account
from google.cloud import firestore

project_id = body['project_id']
user = body['user']
snap_id = body['snapshot_id']
debuggee_id = body['debuggee_id']
db = firestore.Client()
ref = db.collection(u'users').document(user).collection(u'projects').document(project_id)
if ref.get().exists:
    service_account_info = ref.get().to_dict()
else:
    return None, 411

credentials = service_account.Credentials.from_service_account_info(
    service_account_info,
    scopes=['https://www.googleapis.com/auth/cloud-platform'])

service = discovery.build('clouddebugger', 'v2', credentials=credentials)

body只是一本字典,它包含了其他项目的所有信息。我无法理解的是,为什么这不起作用,而是使用from_service_account_file方法来工作。下面的代码将向该方法提供与前一段代码相同的信息,但在json文件中而不是在字典中。也许元素的顺序是不同的,但我认为这一点都不重要。

代码语言:javascript
复制
credentials = service_account.Credentials.from_service_account_file(
    [PATH_TO_PROJECT_KEY_FILE],
    scopes=['https://www.googleapis.com/auth/cloud-platform'])

你能告诉我from_service_account_info方法出了什么问题吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-05-19 22:12:01

问题解决了。当我发布这个问题时,我手动插入了从GCP固定控制台插入的所有关于其他项目的信息。然后,我编写了代码,使它真实和有效。老实说,我不知道为什么它以前不起作用,里面的信息是相同的,格式也是一样的。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61874566

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档