使用Python中的API更新Google Cloud函数的标签

2024-09-30 18:24:01 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试使用API在云函数中添加标签

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()

此代码引发错误updateMask的格式不正确


Tags: nameselfurlcachegetdefservicebody
1条回答
网友
1楼 · 发布于 2024-09-30 18:24:01

根据documentationupdateMask需要一个字符串输入,但是,您正在传递一个列表,这解释了格式不正确的原因

解决方案是将updateMask的值更改为String。例如:

updateMask = 'labels'

如果您希望有多个值,那么它必须位于一个用逗号分隔的字符串上

相关问题 更多 >