正在企业防火墙后面验证 google 云
Authenticating google cloud behind corporate firewall
我正在尝试在工作中使用 Google 云的自然语言 API,我相信我的公司防火墙阻止了 python 和 google 云之间的通信。
在终端中输入以下内容后:
gcloud auth application-default login
我的浏览器打开并成功登录到我的 google 帐户。然而,在我登录后,我得到
ERROR: There was a problem with web authentication. Try running a
gain with --no-launch-browser.
ERROR: (gcloud.auth.application-default.login) Could not reach th
e login server. A potential cause of this could be because you ar
e behind a proxy. Please set the environment variables HTTPS_PROX
Y and HTTP_PROXY to the address of the proxy in the format "proto
col://address:port" (without quotes) and try again.
Example: HTTPS_PROXY=https://192.168.0.1:8080
我想我需要联系我的 IT 部门为我们的防火墙添加例外。有谁知道google云的自然语言处理API的地址/端口是什么?
我无法直接回答您的问题,但我可以提供一些可能解决您的问题的一般指导。
命令
gcloud auth application-default login
是 运行 本地示例代码的便利助手,但由于各种原因,它确实不是最佳的身份验证策略。它使用一个特殊的客户端 ID,它不会总是拥有您的所有配额。
我推荐使用 API 的方式是服务帐户。您可以在 Cloud Console 中使用 API 凭据创建一个服务帐户,然后下载 JSON 密钥。然后将环境变量 GOOGLE_APPLICATION_CREDENTIALS
设置为指向您的文件,假设您使用的是应用程序默认凭据(大多数示例和客户端库使用),它将自动工作。
在 App Engine 和 Compute Engine 上(假设您创建了具有正确范围的 VM)服务帐户默认存在,因此您甚至不需要下载 JSON 和设置环境变量。
您可以使用 API 的另一种方法是创建一个 API 密钥,然后在 URL 末尾使用 ?key=api-key
访问 HTTP 端点。 API 密钥也不太理想(不知道客户是谁,没有范围),但这是一个简单的选择。
在你的情况下,我建议使用 JSON 服务帐户密钥和环境变量,但值得阅读官方 authentication guide.
我正在尝试在工作中使用 Google 云的自然语言 API,我相信我的公司防火墙阻止了 python 和 google 云之间的通信。
在终端中输入以下内容后:
gcloud auth application-default login
我的浏览器打开并成功登录到我的 google 帐户。然而,在我登录后,我得到
ERROR: There was a problem with web authentication. Try running a
gain with --no-launch-browser.
ERROR: (gcloud.auth.application-default.login) Could not reach th
e login server. A potential cause of this could be because you ar
e behind a proxy. Please set the environment variables HTTPS_PROX
Y and HTTP_PROXY to the address of the proxy in the format "proto
col://address:port" (without quotes) and try again.
Example: HTTPS_PROXY=https://192.168.0.1:8080
我想我需要联系我的 IT 部门为我们的防火墙添加例外。有谁知道google云的自然语言处理API的地址/端口是什么?
我无法直接回答您的问题,但我可以提供一些可能解决您的问题的一般指导。
命令
gcloud auth application-default login
是 运行 本地示例代码的便利助手,但由于各种原因,它确实不是最佳的身份验证策略。它使用一个特殊的客户端 ID,它不会总是拥有您的所有配额。
我推荐使用 API 的方式是服务帐户。您可以在 Cloud Console 中使用 API 凭据创建一个服务帐户,然后下载 JSON 密钥。然后将环境变量 GOOGLE_APPLICATION_CREDENTIALS
设置为指向您的文件,假设您使用的是应用程序默认凭据(大多数示例和客户端库使用),它将自动工作。
在 App Engine 和 Compute Engine 上(假设您创建了具有正确范围的 VM)服务帐户默认存在,因此您甚至不需要下载 JSON 和设置环境变量。
您可以使用 API 的另一种方法是创建一个 API 密钥,然后在 URL 末尾使用 ?key=api-key
访问 HTTP 端点。 API 密钥也不太理想(不知道客户是谁,没有范围),但这是一个简单的选择。
在你的情况下,我建议使用 JSON 服务帐户密钥和环境变量,但值得阅读官方 authentication guide.