gpt4 book ai didi

python - 谷歌云功能 : Correct module needed for app_identity to get the APPLICATION_ID

转载 作者:行者123 更新时间:2023-11-28 17:03:54 24 4
gpt4 key购买 nike

如何在 Python Google 云函数中正确导入 app_identity 模块,以便检索 APPLICATION_ID/PROJECT_ID

由于许多解决方案都是专门为 Google App Engine 部署量身定制的,因此这会很有帮助。我部署了一个 GCF 并使用以下代码导入了 app_identity 模块:

from google.appengine.api import app_identity

我遇到了这个错误:ModuleNotFoundError:没有名为“google.appengine”的模块

最佳答案

第一代 App Engine 模块 (google.appengine) 仅存在于原始的 Python 2.7 运行时中。它们不适用于 Cloud Functions 或 App Engine 上的 Python 3.7 运行时。

相反,您可以从环境变量中获取这些东西:

import os
project_id = os.environ['GOOGLE_CLOUD_PROJECT']
function_name = os.environ['FUNCTION_NAME']

关于python - 谷歌云功能 : Correct module needed for app_identity to get the APPLICATION_ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52527893/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com