Google-Cloud-Resource-Manage列表项目403呼叫者未经许可
我创建了一个GCP服务帐户,并为列出组织内部项目的所需权限。当我使用gcloud cli
时,一切都起作用:
gcloud auth activate-service-account --key-file=./key.json
gcloud projects list
# -> List of all projects
但是,当我尝试使用 Google Cloud Resource Manager的Python客户端,我收到403呼叫者没有权限
错误消息。
# pip install google-cloud-resource-manager==1.4.1
from google.oauth2 import service_account
from google.cloud import resourcemanager_v3
# Load gcp credentials
credentials = service_account.Credentials.from_service_account_file('./key.json')
# Create resourcemanager_v3 ProjectsClient
resourcemanager_v3_projects_client = resourcemanager_v3.ProjectsClient(credentials=credentials)
# Initialize request argument(s)
list_projects_request = resourcemanager_v3.ListProjectsRequest(show_deleted=False, parent='')
# Make the request
page_result = resourcemanager_v3_projects_client.list_projects(request=list_projects_request)
# -> Error...
# -> grpc_helpers.py", line 68, in error_remapped_callable
# -> raise exceptions.from_grpc_error(exc) from exc
# -> google.api_core.exceptions.PermissionDenied: 403 The caller does not have permission
Google Cloud Resource Manager的Python客户端是否需要
的其他权限,还是我错过了python代码中的某些内容?gcloud cli
>
I created a GCP service account and assigned the needed permissions for listing the projects inside the organization. When I'm using the gcloud cli
, everything works:
gcloud auth activate-service-account --key-file=./key.json
gcloud projects list
# -> List of all projects
But when I try the "same" with the Python Client for Google Cloud Resource Manager, I receive a 403 The caller does not have permission
error message.
# pip install google-cloud-resource-manager==1.4.1
from google.oauth2 import service_account
from google.cloud import resourcemanager_v3
# Load gcp credentials
credentials = service_account.Credentials.from_service_account_file('./key.json')
# Create resourcemanager_v3 ProjectsClient
resourcemanager_v3_projects_client = resourcemanager_v3.ProjectsClient(credentials=credentials)
# Initialize request argument(s)
list_projects_request = resourcemanager_v3.ListProjectsRequest(show_deleted=False, parent='')
# Make the request
page_result = resourcemanager_v3_projects_client.list_projects(request=list_projects_request)
# -> Error...
# -> grpc_helpers.py", line 68, in error_remapped_callable
# -> raise exceptions.from_grpc_error(exc) from exc
# -> google.api_core.exceptions.PermissionDenied: 403 The caller does not have permission
Does the Python Client for Google Cloud Resource Manager
needs some other permission than the gcloud cli
or do I miss something inside the Python code?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Seems I missed the
parent
Seems I missed the
parent
parameter...The following snipped should list the projects of a specific folder or organization.