使用python导入GCP资源时出现凭据错误

2024-09-23 06:35:28 发布

您现在位置:Python中文网/ 问答频道 /正文

我是编程新手,正在尝试使用python导入现有的GCP资源。但是我在代码本身的开头遇到了这个特殊的“默认凭据错误”。感谢您的帮助

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()

第二个错误

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()

Tags: py错误lineexceptionnotstartusersfile
1条回答
网友
1楼 · 发布于 2024-09-23 06:35:28

Google Cloud API实际上需要一个密钥来知道您使用的是哪个Google帐户以及您的权限。此密钥采用凭据的形式

所以,基本上,你要做的是首先认证你自己。 如果您是在本地编码,最好的方法是首先键入gcloud auth application-default login(如果您想设置默认登录名)或只键入gcloud auth login(但是只有当前使用的命令行将被标识为google cloud)

然后您就可以正常使用GCP API:)

如果需要更多详细信息,请参阅Here

相关问题 更多 >