Windows 10 上的 Google Cloud 数据存储身份验证

use*_*-03 2 authentication google-authentication python-3.x google-cloud-datastore google-cloud-platform

我正在设置一个可以访问互联网的 Windows 10 虚拟机(我可以在虚拟机内的 Chrome 上正常浏览互联网)。我下载并安装了谷歌云SDK。我运行gcloud init并设置了我的帐户和其他选项。据说已经成功完成了。我输入后gcloud info,它显示了正确的信息。问题是,当我运行我编写的包含from google.cloud import datastore. 它存在帐户身份验证问题。仅当我尝试按以下方式实例化数据存储客户端时才会发生此错误:client = datastore.Client()。这当然是有道理的。但是,因为我已经执行了 gcloud init 并使用 gcloud info 对其进行了验证,所以这里没有设置哪些需要设置的内容?

此外,谷歌身份验证库似乎无法正确向某个服务器发出请求。这是日志输出:

2020-09-27 20:26:30 [google.auth._default] DEBUG: Checking None for explicit credentials as part of auth process...
2020-09-27 20:26:30 [google.auth._default] DEBUG: Checking Cloud SDK credentials as part of auth process...
2020-09-27 20:26:30 [google.auth._default] DEBUG: Cloud SDK credentials not found on disk; not using them
2020-09-27 20:26:30 [google.auth._default] DEBUG: Checking for App Engine runtime as part of auth process...
2020-09-27 20:26:30 [google.auth._default] DEBUG: No App Engine library was found so cannot authentication via App Engine Identity Credentials.
2020-09-27 20:26:30 [google.auth.transport._http_client] DEBUG: Making request: GET http://169.254.169.254
2020-09-27 20:26:33 [google.auth.compute_engine._metadata] WARNING: Compute Engine Metadata server unavailable onattempt 1 of 3. Reason: timed out
2020-09-27 20:26:33 [google.auth.transport._http_client] DEBUG: Making request: GET http://169.254.169.254
2020-09-27 20:26:36 [google.auth.compute_engine._metadata] WARNING: Compute Engine Metadata server unavailable onattempt 2 of 3. Reason: timed out
2020-09-27 20:26:36 [google.auth.transport._http_client] DEBUG: Making request: GET http://169.254.169.254
2020-09-27 20:26:39 [google.auth.compute_engine._metadata] WARNING: Compute Engine Metadata server unavailable onattempt 3 of 3. Reason: timed out
2020-09-27 20:26:39 [google.auth._default] WARNING: Authentication failed using Compute Engine authentication due to unavailable metadata server.
Run Code Online (Sandbox Code Playgroud)

调用堆栈末尾的实际错误是:

  File "C:\Users\<user>\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
Run Code Online (Sandbox Code Playgroud)

编辑:请注意,此处提到了日志中列出的此 IP 地址: https://serverfault.com/questions/427018/what-is-this-ip-address-169-254-169-254/427022 它看起来像它的仅本地 IP 地址。但这很奇怪,因为该虚拟机有一个 DHCP 分配的 IP 地址,甚至与主机 IP 不同。我正在使用虚拟机。我尝试了两种网络类型设置:桥接适配器和 NAT。两者都不在这里工作。这是虚拟机网络的错误还是我没有意识到的其他原因?

小智 8

对我来说(因为这是一台新机器,并且我已经在之前的机器上使用了所有 python 代码和 gcp 帐户设置)。问题是在我的东西开始工作之前gcloud init我也需要运行。gcloud auth application-default login