简体   繁体   English

使用 ZA7F5F35426B92741117231B5638 中的 API 更新 Google Cloud Function 的 label

[英]Update the label of Google Cloud Function using API in Python

I am trying to add labels in the cloud function using API我正在尝试使用 API 在云 function 中添加标签

class MemoryCache(Cache):
    _CACHE = {}
    def get(self, url):
        return MemoryCache._CACHE.get(url)
    def set(self, url, content):
        MemoryCache._CACHE[url] = content

    scopes = ['https://www.googleapis.com/auth/cloud-platform']
    credentials, project_id = google.auth.default(scopes)
    service = build('cloudfunctions', 'v1', credentials=credentials, cache=MemoryCache())
    name='projects/my-project/locations/us-central1/functions/function-1'
    result_call = service.projects().locations().functions().get(name=name, x__xgafv=None).execute()
    print(result_call)

    updateMask = ['labels']
    body = {'labels': {'type': 'testing'}}
    result = service.projects().locations().functions().patch(name=name, updateMask=updateMask,
    body=body,
    x__xgafv=None).execute()

This code throws an error the format of updateMask is not correct此代码抛出错误updateMask的格式不正确

Based from the documentation , updateMask requires a String input however, you're passing a List and that explains why the format is incorrect.根据文档updateMask需要一个字符串输入,但是,您传递的是一个列表,这解释了格式不正确的原因。

The solution is to change the value of updateMask to String.解决方法是将updateMask的值改为String。 For example:例如:

updateMask = 'labels'

If there's a case where you wish to you have multiple values, then it must to be on a single string separated with a comma.如果您希望有多个值,那么它必须位于用逗号分隔的单个字符串上。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在 Python 中使用 API 创建 Google Cloud Function - Create Google Cloud Function using API in Python 将 Google Calendar API 与 Python 3.7 Google Cloud Function 结合使用 - Using Google Calendar API with a Python 3.7 Google Cloud Function 如何使用 Python api 更新 Google Cloud 调度程序 - How to update the Google Cloud scheduler with Python api 使用 Python 的 Google Cloud Billing API - Google Cloud Billing API using Python 使用谷歌云函数生成python脚本 - Using google cloud function to spawn a python script GCP - 将数据从 REST API 插入/加载到 BigQuery,使用 Google Cloud Function 和 ZA7F5F35426B927824717BFCFC11 - GCP - Insert/Load Data to BigQuery from REST API using Google Cloud Function with Python Python 谷歌云 Function - Python Google Cloud Function 使用 Python 和 SQLAlchemy 从谷歌云 Function 连接到云 SQL - Connecting to Cloud SQL from Google Cloud Function using Python and SQLAlchemy 在Google云端点项目(Python)中使用其他Google API - Using other Google API's in a Google cloud endpoints project (Python) 如何使用 Python Function 在 Google Cloud Functions 中正确调用 API - How to correctly call an API in Google Cloud Functions with a Python Function
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM