我正在编写一个基于GCP服务的应用程序,我需要访问一个外部项目。我将我需要访问的另一个项目的身份验证文件的信息存储在Firestore数据库中。我读了这份文件并尝试应用它,但我的代码不起作用。正如文档所述,我传递给身份验证方法的是dictionarystr,str。这是我的密码:
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文件中而不是在字典中。也许元素的顺序是不同的,但我认为这一点都不重要。
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方法出了什么问题吗?
发布于 2020-05-19 22:12:01
问题解决了。当我发布这个问题时,我手动插入了从GCP固定控制台插入的所有关于其他项目的信息。然后,我编写了代码,使它真实和有效。老实说,我不知道为什么它以前不起作用,里面的信息是相同的,格式也是一样的。
https://stackoverflow.com/questions/61874566
复制相似问题