【问题标题】:How to use service account in Python on GAE?如何在 GAE 上使用 Python 中的服务帐户?
【发布时间】:2018-05-09 00:04:05
【问题描述】:

我想知道如何在 Google App Engine 标准环境中使用服务帐户。 我编写了一些如下代码来使用正确的 JSON 密钥文件访问 BigQuery。

from google.cloud import bigquery
....
bigquery_client = bigquery.Client.from_service_account_json(proper_path_to_json_key)
list(bigquery_client.list_datasets())

当我在本地 Python 解释器上运行代码时,它运行正常,但在本地 dev_appserver.py 上运行时,结果惨遭失败并出现以下错误。

TransportError: ('Connection aborted.', error(13, 'Permission denied'))

当它在 GAE 上运行时,它仍然失败,但它的错误消息如下所示。

TransportError: ('Connection broken: IncompleteRead(208 bytes read)', IncompleteRead(208 bytes read))

我认为这个错误是由 GAE 对此处描述的出站流量的限制引起的 https://cloud.google.com/appengine/docs/standard/python/issue-requests 但我不知道如何解决它。

在 GAE 环境中使用服务帐户的最佳方式是什么?

【问题讨论】:

    标签: python google-app-engine google-cloud-platform service-accounts


    【解决方案1】:

    很遗憾,App Engine Standard 尚不支持 Google 客户端库,例如您尝试使用的 BigQuery 库,如 in this GitHub topic 所述,尽管它正在进行中。

    或者,如果符合您的要求,您可以尝试在 App Engine Flexible 中进行部署,或者尝试使用 Google API Client Libraries

    关于在 App Engine 中使用服务帐户的问题,您可以使用运行该服务时可用的默认内置服务帐户,也可以创建自定义服务帐户。您可以在documentation 中找到有关在 App Engine 标准中使用服务帐户的更多信息。

    【讨论】:

      猜你喜欢
      • 2014-09-07
      • 2014-12-13
      • 2013-09-01
      • 2013-04-08
      • 1970-01-01
      • 1970-01-01
      • 2023-01-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多