python - GCP 使用 gcloud auth(不是服务帐户)作为最终用户进行身份验证
问题描述
在我的 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
我不想使用服务帐户。我想使用最终用户凭据进行身份验证(不使用流)。
解决方案
解决方案:
跑
gcloud auth application-default login
在 Windows 机器上,并以您想要的用户身份登录。
推荐阅读
- python - 用for循环创建多个图?
- javascript - 如何在javascript中的交替点击时调用弹出窗口?
- ios - 如何在swift中为属性文本设置粗体样式的自定义字体?
- python - Python Beautifulsoup - 单击加载更多按钮
- django-rest-framework - 在 swagger API Django 中对用户进行身份验证
- c - 计算算法的执行时间
- arrays - 下标超出范围错误,当 Watch 显示它肯定在范围内时
- pentaho - Pentaho Report Designer 5.4:如何在 BeahShell 脚本函数中访问自定义表格?
- r - 如何使用 Amelia 的估算数据创建一个函数来运行多个回归模型?
- flutter - 颤振 - NoSuchMethodError:类'_MapStream
' 没有实例方法 'then'