【发布时间】:2021-01-06 09:28:49
【问题描述】:
为了从我的项目中检索监控指标,我使用了以下 Python 代码:
from google.cloud import monitoring_v3
from google.oauth2 import service_account
from googleapiclient import discovery
credentials = service_account.Credentials.from_service_account_file(
r'D:\GCP\credentials\blahblah-04e8fd0245b8.json')
service = discovery.build('compute', 'v1', credentials=credentials)
client = monitoring_v3.MetricServiceClient()
project_name = f"projects/{blahblah-300807}"
resource_descriptors = client.list_monitored_resource_descriptors(
name=project_name)
for descriptor in resource_descriptors:
print(descriptor.type)
我做得很好。我正确地提供了凭据信息的文件路径,但收到了以下错误消息:
raise exceptions.DefaultCredentialsError(_HELP_MESSAGE)
google.auth.exceptions.DefaultCredentialsError: \
Could not automatically determine credentials. \
Please set GOOGLE_APPLICATION_CREDENTIALS or explicitly create \
credentials and re-run the application. \
For more information, please see \
https://cloud.google.com/docs/authentication/getting-started
我什至检查了该链接并尝试了替代方法,但仍然没有用。我该如何纠正这个问题?我是不是搞错了?
【问题讨论】:
标签: python google-app-engine google-cloud-platform credentials