-1

I was trying this pub/sub client tutorial, and got this error in publisher.py

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

when I call this part.

publisher = pubsub_v1.PublisherClient()

I am a member of a GCP group which has already pubsub.publisher, pubsub.subscriber roles. And I registered my account on my local machine. So, if I use CLI command on terminal like

gcloud pubsub topics publish <topic-name> --message="help me"

It succeeds.

I can see that python script can be seen as a service, so it needs service account. But is there any way to use my group's credentials in python script too, or should I use a service account?


(12.03.2021 updated 1) Thanks for answering guys, (Sorry, I'm noob in GCP). I have no roles to give specific roles to a service account, which means that I cannot make a service account that has roles pubsub.publisher and pubsub.subscriber. (this is our department's policy. is it kind of wired??) So for the tutorials in local machine, I just want to use groups IAM (user account IAM) for a credentials. Is there no way not to use service account?? (I just thought that there is a way even though python script can be seen as a service)


(12.03.2021 updated 2)

gcloud auth application-default login worked as suggested by here

2
  • you may want to take a look at this topic stackoverflow.com/questions/44328277/… Commented Dec 2, 2021 at 11:49
  • @lukaszberwid Thanks, I applied gcloud auth application-default login and it works! Commented Dec 3, 2021 at 3:59

1 Answer 1

0

Add your service account email in your Google Groups and Voilà!

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for answering, but I have no roles to give specific roles to a service account, which means that I cannot make a service account that has roles pubsub.publisher and pubsub.subscriber. Is there no way not to use service account? (I updated my question)
You can avoid to use a service account in your local environment and use your own credential. But, when your app run on Google Cloud, you can't (in fact I prefer not to say how to achieve that hack and very bad practice) use your own credential, you will have to use a service account.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.