[英]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.