简体   繁体   English

python 中的 Google 神器注册表 list_tags - 包含无效参数

[英]Google artifact registry list_tags in python - contains invalid argument

I'm a code newbie so please be kind:) I've got my google credentials set and I've checked the documentation for the python library for artifact registry (v1), but clearly doing something daft, as I'm receiving this response back - google.api_core.exceptions.InvalidArgument: 400 Request contains an invalid argument.我是代码新手所以请善待:)我已经设置了我的谷歌凭据并且我已经检查了用于工件注册表(v1)的 python 库的文档,但显然做了一些愚蠢的事情,因为我收到了这个回复 - google.api_core.exceptions.InvalidArgument: 400 Request contains an invalid argument.

Here's my code:这是我的代码:

from google.cloud import artifactregistry_v1

# Using Application Default Credentails is easiest
# export GOOGLE_APPLICATION_CREDENTIALS=/path/to/key.json
client = artifactregistry_v1.ArtifactRegistryClient()

# Best obtained from the environment
project = "**REDACTED**" 
location = "europe-west2"
repository = "test"

parent = f"projects/{project}/locations/{location}/repositories/{repository}"

request = artifactregistry_v1.ListTagsRequest(parent=parent)

page_result = client.list_tags(request=request)

for response in page_result:
    print(response)

Here's the official docs, I can't work out what I've done wrong: https://cloud.google.com/python/docs/reference/artifactregistry/latest/google.cloud.artifactregistry_v1.services.artifact_registry.ArtifactRegistryClient#google_cloud_artifactregistry_v1_services_artifact_registry_ArtifactRegistryClient_list_tags这是官方文档,我不知道我做错了什么: https ://cloud.google.com/python/docs/reference/artifactregistry/latest/google.cloud.artifactregistry_v1.services.artifact_registry.ArtifactRegistryClient# google_cloud_artifactregistry_v1_services_artifact_registry_ArtifactRegistryClient_list_tags

EDIT编辑

Just seen on the Google docs for the Class ListTagsRequest ( here ) it says parent expects a string (which is what i've done), but noticed in PyCharm it's highlighted and telling me expected type 'Dict', and got 'str' instead ....刚刚在类ListTagsRequest的 Google 文档上看到( 这里)它说parent期望一个字符串(这是我所做的),但在 PyCharm 中注意到它被突出显示并告诉我expected type 'Dict', and got 'str' instead ....

I was finally able to find the correct code:我终于能够找到正确的代码:

from google.cloud import artifactregistry_v1


def get_package_tags_from_artifact_registry():
    # Using Application Default Credentails is easiest
    # export GOOGLE_APPLICATION_CREDENTIALS=/path/to/key.json
    client = artifactregistry_v1.ArtifactRegistryClient()

    # Best obtained from the environment
    project = "{project_id}"
    location = "{location}"
    repository = "{repository}"
    package_name = "{package_name}"

    parent = f"projects/{project}/locations/{location}/repositories/{repository}/packages/{package_name}"

    request = artifactregistry_v1.ListTagsRequest(
        parent=parent
    )

    page_result = client.list_tags(
        request=request
    )

    for response in page_result:
        print(response)

    return page_result


if __name__ == '__main__':
    result = get_package_tags_from_artifact_registry()

I checked from this doc and tested with a parent path including the package name.我从此文档中进行了检查,并使用包含package名称的父路径进行了测试。

暂无
暂无

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

相关问题 谷歌云容器注册表错误:“无法触发构建:请求包含无效参数。” - google cloud container registry error: "Failed to trigger build: Request contains an invalid argument." 如何在谷歌容器注册表中列出图像和标签 - How do I list images and tags in google container registry Google Artifact Registry 和 Jenkins:防止部署具有高或严重漏洞的容器 - Google Artifact Registry and Jenkins: prevent deploy containers with high or critical vulnerabilities 如何通过 python 脚本在 Google 容器注册表 (GCR) 中列出 docker 图像? - How to list docker images in Google container registry (GCR) through python script? firebase 云消息传递请求包含无效参数 - firebase cloud messaging Request contains an invalid argument GCP:如何修剪/维护工件注册表存储? - GCP: How to prune/maintain Artifact Registry storage? 带有 PubSub 的 GKE 上的 Google Healthcare API - INVALID_ARGUMENT - Google Healthcare API on GKE with PubSub - INVALID_ARGUMENT 如何自动从 Artifact Registry 中删除图像 - How to remove an image from Artifact Registry automatically 命令删除工件注册表的所有图像版本,除了最新的? - Command To Delete All Image Versions of Artifact Registry Except Latest? stackdriver 查询抛出 400 GoogleJsonResponseException:400 错误请求“请求包含无效参数” - stackdriver query throws 400 GoogleJsonResponseException: 400 Bad Request "Request contains an invalid argument"
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM