英文:
google.api_core.exceptions.InvalidArgument: 400 invalid repository
问题
I'm here to provide the translation of the code and relevant information:
from google.cloud import artifactregistry_v1
def sample_create_repository():
# 创建客户端
print("正在测试代码")
client = artifactregistry_v1.ArtifactRegistryClient.from_service_account_file(filename='<path_to_sa.json>')
# 初始化请求参数
request = artifactregistry_v1.CreateRepositoryRequest(
parent="projects/p1/locations/us",
repository={'name': 'projects/p1/locations/us/repositories/testrepo', 'format_': 'DOCKER'}
)
# 发送请求
operation = client.create_repository(request=request)
print("等待操作完成...")
response = operation.result()
# 处理响应
print(response)
sample_create_repository()
你遇到的错误是因为 repository 参数的格式不正确。确保它的值与项目、位置、存储库名称和格式的格式与你的项目配置匹配。如果需要更多帮助,请参考相关文档。
英文:
I am trying to create a repository in Artifact registry of GCP using Python API by following below link.
Below is the code I am using.
from google.cloud import artifactregistry_v1
def sample_create_repository():
# Create a client
print("Testing the code")
client = artifactregistry_v1.ArtifactRegistryClient.from_service_account_file(filename='<path_to_sa.json>')
# Initialize request argument(s)
request = artifactregistry_v1.CreateRepositoryRequest(parent="projects/p1/locations/us",repository={'name':'projects/p1/locations/us/repositories/testrepo','format_':'DOCKER'})
# Make the request
operation = client.create_repository(request=request)
print("Waiting for operation to complete...")
response = operation.result()
# Handle the response
print(response)
sample_create_repository()
I am getting below error for this code, Can anyone from the community suggest the correct format here,
raise exceptions.from_grpc_error(exc) from exc
google.api_core.exceptions.InvalidArgument: 400 invalid repository: generic::unknown: invalid repository name: "projects/p1/locations/us/repositories/": invalid repository name: projects/p1/locations/us/repositories/
parent format I have taken this doc as reference - https://cloud.google.com/artifact-registry/docs/reference/rest
repository format I have taken this doc as reference - https://cloud.google.com/python/docs/reference/artifactregistry/latest/google.cloud.artifactregistry_v1.types.Repository
答案1
得分: 2
你需要在CreateRepositoryRequest中提供存储库ID。对于Create操作,Repository.Name会被忽略。(大多数Google API都会类似行事,详见https://google.aip.dev/133#user-specified-ids)
英文:
You need to provide the repository id in the CreateRepositoryRequest itself. Repository.Name is ignored for Create. (Most Google apis will behave similarly, see https://google.aip.dev/133#user-specified-ids)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论