googleapis / python-artifact-registry

This library has moved to https://github.com/googleapis/google-cloud-python/tree/main/packages/google-cloud-artifact-registry
Apache License 2.0
11 stars 13 forks source link

Any request attempt fails with HTTP code 400 #118

Closed pawel-chmielak-deepsense closed 2 years ago

pawel-chmielak-deepsense commented 2 years ago

An attempt to use any method fails with code "400 Invalid resource field value in the request.". The example code uses list_repositories, but any other request will fail as well.

Environment details

Steps to reproduce

  1. Run the example code, but replace SERVICE_ACCOUNT_JSON_PATH with a path to you service account JSON.

Code example

from google.cloud.artifactregistry import ArtifactRegistryClient      

def list_images():
    client = ArtifactRegistryClient.from_service_account_file(SERVICE_ACCOUNT_JSON_PATH)
    return client.list_repositories()

list_images()

Stack trace

Traceback (most recent call last):
  File "/home/user_x/project/venv/lib/python3.9/site-packages/google/api_core/grpc_helpers.py", line 66, in error_remapped_callable
    return callable_(*args, **kwargs)
  File "/home/user_x/project/venv/lib/python3.9/site-packages/grpc/_channel.py", line 946, in __call__
    return _end_unary_response_blocking(state, call, False, None)
  File "/home/user_x/project/venv/lib/python3.9/site-packages/grpc/_channel.py", line 849, in _end_unary_response_blocking
    raise _InactiveRpcError(state)
grpc._channel._InactiveRpcError: <_InactiveRpcError of RPC that terminated with:
    status = StatusCode.INVALID_ARGUMENT
    details = "Invalid resource field value in the request."
    debug_error_string = "{"created":"@1642778818.173243354","description":"Error received from peer ipv4:142.250.203.138:443","file":"src/core/lib/surface/call.cc","file_line":1074,"grpc_message":"Invalid resource field value in the request.","grpc_status":3}"
>

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/user_x/project/app/app/services/external/artifact_registry.py", line 11, in <module>
    list_images()
  File "/home/user_x/project/app/app/services/external/artifact_registry.py", line 8, in list_images
    return client.list_repositories()
  File "/home/user_x/project/venv/lib/python3.9/site-packages/google/cloud/artifactregistry_v1/services/artifact_registry/client.py", line 546, in list_repositories
    response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,)
  File "/home/user_x/project/venv/lib/python3.9/site-packages/google/api_core/gapic_v1/method.py", line 154, in __call__
    return wrapped_func(*args, **kwargs)
  File "/home/user_x/project/venv/lib/python3.9/site-packages/google/api_core/grpc_helpers.py", line 68, in error_remapped_callable
    raise exceptions.from_grpc_error(exc) from exc
google.api_core.exceptions.InvalidArgument: 400 Invalid resource field value in the request. [reason: "RESOURCE_PROJECT_INVALID"
domain: "googleapis.com"
metadata {
  key: "method"
  value: "google.devtools.artifactregistry.v1.ArtifactRegistry.ListRepositories"
}
metadata {
  key: "service"
  value: "artifactregistry.googleapis.com"
}
]

Process finished with exit code 1
averikitsch commented 2 years ago

Hello, This error seems to be coming from the lack of a request object being passed into the list_repositories method.

    # Initialize request argument(s)
    request = artifactregistry_v1.ListRepositoriesRequest(
        parent="projects/PROJECT/locations/LOCATION",
    )

    # Make the request
    page_result = client.list_repositories(request=request)

Where PROJECT and LOCATION are your values.

Please reopen if you continue to experience issues.