GCP 松弛教程 'slash command';未能部署 google 云功能

GCP slack tutorial 'slash command'; failed to deploy google cloud function

在经历 tutorial for creating a basic slack app with google cloud 时,部署阶段失败并显示:

>gcloud functions deploy kg_search --runtime python37 --trigger-http Deploying function (may take a while - up to 2 minutes)...failed. ERROR: (gcloud.functions.deploy) OperationError: code=3, message=Function failed on loading user code. Error message: 'API_KEY'

正在尝试解决这个问题

为了解决这个问题,我返回到 main.py 文件,并在第 29 行找到以下内容:
developerKey=os.environ['API_KEY'] or config['KG_API_KEY'])。我把它换成 developerKey=config['KG_API_KEY'])

如果有人知道如何避免错误消息并依靠 or 语句从配置中提取 API_KEY,请在此处发表评论并获得额外积分并发送 PR 至 this 文件.

在第 29 行中,代码 os.environ['API_KEY'] 试图从 shell 环境变量中获取 API_KEY,但由于它未定义,程序崩溃了。 正如您所发现的,当您删除 or 语句的第一部分时,不再引发异常。

部署时设置环境变量的方法Google Cloud Functions 解释here

你能重试部署步骤 运行 gcloud functions deploy kg_search --set-env-vars API_KEY=YOUR-API-KEY --runtime python37 --trigger-http 看看它是否有效吗?