简体   繁体   中英

Credentials error while using python to import GCP resources

I am new to programming and am trying to import the existing GCP resources using python. But I am getting this particular "Default Credentials Error" at the starting of the code itself. Any help is appreciated.

Exception has occurred: 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
  File "C:\Users\dilee\Desktop\Python\GCP\start.py", line 4, in <module>
    publisher = pubsub_v1.PublisherClient()

Second Error

Exception has occurred: DefaultCredentialsError
File "C:\Users\dilee\Desktop\PythonGCP\learning-project-311506-1b36ea6ccc86.json" was not found.
  File "C:\Users\dilee\Desktop\PythonGCP\start.py", line 6, in <module>
    publisher = pubsub.PublisherClient()

Google Cloud API needs actually a key to know which google account you are using and what are your rights. This key takes the form of credentials.

So basically, what you have to do is to authentificate yourself first. If you are coding locally, the best method is to type first gcloud auth application-default login (if you want to set your default login) or only gcloud auth login (but then only the currently used command line will be identificated to google cloud).

Then you'd be able to use GCP API normally:)

See Here if you need more details.

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