在我的GCP VM(ubuntu)服务器上,如果我运行:
gcloud init
在终端中输入,然后以我的用户名登录(没有服务帐户),例如my.name@companyname.com
,然后我就可以作为用户自身进行身份验证,并且可以对所有与gcp相关的python函数进行身份验证。
>>> import google.auth
>>> credentials, project = google.auth.default()
UserWarning: Your application has authenticated using end user credentials from Google Cloud SDK without a quota project. You might receive a "quota exceeded" or "API not enabled" error. We recommend you rerun `gcloud auth application-default login` and make sure a quota project is added. Or you can use service accounts instead. For more information about service accounts, see https://cloud.google.com/docs/authentication/
warnings.warn(_CLOUD_SDK_CREDENTIALS_WARNING)
但是,当我在本地Windows计算机上执行相同的过程时,出现此错误:
>>> import google.auth
>>> credentials, project = google.auth.default()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\ProgramData\Anaconda3\lib\site-packages\google\auth\_default.py", line 354, in default
raise exceptions.DefaultCredentialsError(_HELP_MESSAGE)
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
我不想使用服务帐户。我想使用最终用户凭据进行身份验证(不使用流程)。
答案 0 :(得分:0)
解决方案:
运行
gcloud auth application-default login
在Windows计算机中,然后以所需的用户身份登录。