Skip to content
This repository has been archived by the owner on Sep 5, 2023. It is now read-only.

list_projects does not work, but search_projects does. #145

Closed
fxdgear opened this issue Dec 16, 2021 · 3 comments
Closed

list_projects does not work, but search_projects does. #145

fxdgear opened this issue Dec 16, 2021 · 3 comments
Assignees
Labels
api: cloudresourcemanager Issues related to the googleapis/python-resource-manager API. priority: p2 Moderately-important priority. Fix may not be included in next release. 🚨 This issue needs some love. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@fxdgear
Copy link

fxdgear commented Dec 16, 2021

Environment details

  • OS type and version:
  • Python version: 3.9.6
  • pip version: 21.3.1
  • google-cloud-resource-manager version: 1.3.3

My service account has the following permissions:

  • resourcemanager.projects.get
  • resourcemanager.projects.list

list_projects - Fails

from google.cloud import resourcemanager

client = resourcemanager.ProjectsClient.from_service_account_json("creds.json")

for project in client.list_projects():
    print(project)

search_projects - Succeeds

from google.cloud import resourcemanager

client = resourcemanager.ProjectsClient.from_service_account_json("creds.json")

# List all projects you have access to
for project in client.search_projects():
    print(project)

Stack trace

Traceback (most recent call last):
  File "/app/gcp_utils.py", line 12, in <module>
    for project in client.list_projects():
  File "/usr/local/lib/python3.9/site-packages/google/cloud/resourcemanager_v3/services/projects/client.py", line 519, in list_projects
    response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,)
  File "/usr/local/lib/python3.9/site-packages/google/api_core/gapic_v1/method.py", line 154, in __call__
    return wrapped_func(*args, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/google/api_core/retry.py", line 283, in retry_wrapped_func
    return retry_target(
  File "/usr/local/lib/python3.9/site-packages/google/api_core/retry.py", line 190, in retry_target
    return target()
  File "/usr/local/lib/python3.9/site-packages/google/api_core/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
@product-auto-label product-auto-label bot added the api: cloudresourcemanager Issues related to the googleapis/python-resource-manager API. label Dec 16, 2021
@parthea
Copy link
Contributor

parthea commented Dec 17, 2021

Hi @fxdgear,

TL;DR; use this code

from google.cloud import resourcemanager

client = resourcemanager.ProjectsClient.from_service_account_json("creds.json")

for project in client.list_projects(<The name of the parent resource to list projects under>):
    print(project)

I was able to re-create the issue with your code snippet. As a first step, I went to the Try this API
section for the Resource Manager V3 list_projects reference documentation. I noticed that the parent parameter is required. Once I provided a parent parameter, I received a valid response. I've checked that the parent parameter is also listed as a required parameter in the docs here. Regretfully we don't have samples in this repository. We are tracking the issue here.

I'm going to keep this issue open as we should improve the error message to let users know that a required parameter is missing.

@parthea parthea added type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. priority: p2 Moderately-important priority. Fix may not be included in next release. labels Dec 17, 2021
@yoshi-automation yoshi-automation added 🚨 This issue needs some love. and removed 🚨 This issue needs some love. labels Mar 17, 2022
@yoshi-automation yoshi-automation added the 🚨 This issue needs some love. label Jun 15, 2022
@parthea
Copy link
Contributor

parthea commented Apr 15, 2023

I'm going to close this issue as a response was provided in #145 (comment). Please open a new issue if the error re-appears.

@parthea parthea closed this as completed Apr 15, 2023
@parthea
Copy link
Contributor

parthea commented Apr 15, 2023

I've confirmed that the error message says detail: "The required field \'parent\' is missing in the request. when the required parameter is missing.

image

@parthea parthea self-assigned this Apr 18, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
api: cloudresourcemanager Issues related to the googleapis/python-resource-manager API. priority: p2 Moderately-important priority. Fix may not be included in next release. 🚨 This issue needs some love. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet
Development

No branches or pull requests

3 participants