-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

zzaebok
  • 31
  • 7
  • you may want to take a look at this topic https://stackoverflow.com/questions/44328277/how-to-auth-to-google-cloud-using-service-account-in-python – lukaszberwid Dec 02 '21 at 11:49
  • @lukaszberwid Thanks, I applied `gcloud auth application-default login` and it works! – zzaebok Dec 03 '21 at 03:59

1 Answers1

0

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

guillaume blaquiere
  • 66,369
  • 2
  • 47
  • 76
  • 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) – zzaebok Dec 03 '21 at 01:04
  • 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. – guillaume blaquiere Dec 03 '21 at 13:46