简体   繁体   中英

How to auth using user authentication in python ? because I need to list out all the project IDs

I need the list of project ids in gcp using python

I am trying this

    from google.cloud.resourcemanager import ProjectsClient
    for project in ProjectsClient().list_projects():
        print(project.display_name)

but I am getting the following error

google.api_core.exceptions.PermissionDenied: 403 The caller does not have permission

I think this could be resolved if I use a user account authentication instead of service account authentication.

Please suggest me a method to achieve this

Your questions shows little effort from you in finding the answer for yourself. This is discouraged and your question may be downvoted|closed.

You don't include details of the authentication that you're using. Permission Denied would result from including no credentials as well as including incorrect credentials.

You may use either a user account or a service account to auth the client code and you (are probably?) using Application Default Credentials (ADCs) .

To switch from using GOOGLE_APPLICATION_CREDENTIALS pointing to a Service Account key to User-based credentials, you must unset GOOGLE_APPLICATION_CREDENTIALS and gcloud auth application-default login .

NOTE It is the permissions (usually through roles) that are bound to the account not whether the account is a User account or Service Account that makes the difference to whether your code will be authorized.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM