【问题标题】:How to deploy basic python functions (with packages) on Google Cloud Functions如何在 Google Cloud Functions 上部署基本的 Python 函数(带包)
【发布时间】:2019-09-23 18:40:36
【问题描述】:

我正在尝试部署一个基本的 python 函数,该函数通过 Google Functions(浏览器编辑器)使用 HTTP 触发器调用 api。

这是我要部署的功能:

import requests
import json

def call_api():

    API_URL = 'https://some-api.com/v1'
    API_TOKEN = 'some-api-token'

    result = requests.get(API_URL+"/contacts?access_token="+API_TOKEN).json()
    print(result)

call_api()

我的 requirements.txt 包含:

requests==2.21.0

但是,每次我尝试部署该功能时,都会出现以下错误:

Unknown resource type

我做错了什么?该功能在我的本地机器上运行良好。

【问题讨论】:

    标签: python-3.x http google-cloud-platform google-cloud-functions


    【解决方案1】:

    更多信息请参考Writing HTTP Functions。这是我在查看您的代码时想到的:

    • 缺少request 参数(def call_api(request):
    • 末尾缺少返回(不需要打印,返回给调用者即可)
    • 在文件末尾调用call_api()只会在本地调用函数,CF不需要这个

    确保您使用gcloud functions deploy call_api --runtime python37 --trigger-http进行部署

    【讨论】:

      猜你喜欢
      • 2020-11-03
      • 1970-01-01
      • 2019-12-30
      • 2022-07-28
      • 2019-11-14
      • 2019-10-06
      • 2020-11-14
      • 2018-05-18
      相关资源
      最近更新 更多