【问题标题】:Cloud Function not deploying correctly云功能未正确部署
【发布时间】:2022-01-07 05:43:18
【问题描述】:

我正在尝试从下面提到的功能修补(更新)云调度程序中存在的作业。该函数使用 api 更新 Job 的属性(access_token)。但是它没有正确部署。代码有问题吗?

导入base64 从 pprint 导入 pprint

从 googleapiclient 导入发现 从 oauth2client.client 导入 GoogleCredentials

def hello_pubsub(event, context):

credentials = GoogleCredentials.get_application_default()
service = discovery.build('cloudscheduler', 'v1', credentials=credentials)

name = 'projects/XYZ/locations/TempLocation/jobs/TestTopic' 
job_body = {
  "name": "temp",
  "description": temp,
 
 "pubsubTarget": {
    "topicName": "projects/XYZ/topics/TestTopic",
    "attributes": {
    "access_token": "blabla"
    }
  },
  "httpTarget": {
      "uri": "https://cloudscheduler.googleapis.com/v1/projects/XYZ/locations/TempLocation/jobs/TestTopic",
      "httpMethod": "POST",
      "headers": {
        "Content-Type": "application/json",
      },

      "oauthToken": {
        "serviceAccountEmail": "xyz@gmail.com",
      }       
  }
}


request = service.projects().locations().jobs().patch(name=name, body=job_body)
response = request.execute()
pprint(response)

【问题讨论】:

  • 这是我在日志中发现的错误 Downloading oauth2client-4.0.0-py2.py3-none-any.whl (184 kB) 错误:找不到满足 googleapiclient 要求的版本(来自 -r requirements.txt(第 4 行))(来自版本:无)错误:找不到 googleapiclient 的匹配分发(来自 -r requirements.txt(第 4 行));错误 ID:0ea8a540
  • 尝试 pip install google-api-python-client 指定here。或者你可以查看thread1 & thread2

标签: google-cloud-platform google-cloud-functions google-cloud-scheduler google-cloud-api-gateway


【解决方案1】:

如@Akshansha Singhal 所述,请参考here

对于“googleapiclient”,最新的默认版本 2.0 仅在 Python 3.6+ 上受支持。

如果在 Python 2.7+ 上,请使用版本 1.x。

您可以在“requirements.txt”中配置这些版本依赖项。

【讨论】:

    猜你喜欢
    • 2018-08-09
    • 2020-12-13
    • 2017-08-08
    • 1970-01-01
    • 2021-08-26
    • 2020-11-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多