【问题标题】:StatusCode.UNIMPLEMENTED when making Vertex AI API callStatusCode.UNIMPLEMENTED 进行 Vertex AI API 调用时
【发布时间】:2023-01-26 12:12:47
【问题描述】:

我有一个简单的 Python 应用程序,它调用 Vertex AI API,但在运行时失败,我不明白为什么。应用如下:

from google.cloud import aiplatform_v1

def sample_list_datasets():
    client = aiplatform_v1.DatasetServiceClient()
    request = aiplatform_v1.ListDatasetsRequest(
        parent="projects/MYPROJECT/locations/us-central1",
    )
    page_result = client.list_datasets(request=request)
    for response in page_result:
        print(response)

sample_list_datasets()

运行时,它失败并显示:

E0126 03:52:04.146970105   22462 hpack_parser.cc:1218]                 Error parsing metadata: error=invalid value key=content-type value=text/html; charset=UTF-8
Traceback (most recent call last):
  File "/home/kolban/projects/vertex-ai/datasets/env/lib/python3.7/site-packages/google/api_core/grpc_helpers.py", line 72, in error_remapped_callable
    return callable_(*args, **kwargs)
  File "/home/kolban/projects/vertex-ai/datasets/env/lib/python3.7/site-packages/grpc/_channel.py", line 946, in __call__
    return _end_unary_response_blocking(state, call, False, None)
  File "/home/kolban/projects/vertex-ai/datasets/env/lib/python3.7/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.UNIMPLEMENTED
        details = "Received http2 header with status: 404"
        debug_error_string = "UNKNOWN:Error received from peer ipv4:108.177.120.95:443 {created_time:"2023-01-26T03:52:04.147076255+00:00", grpc_status:12, grpc_message:"Received http2 header with status: 404"}"
>

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

Traceback (most recent call last):
  File "run.py", line 25, in <module>
    sample_list_datasets()
  File "run.py", line 19, in sample_list_datasets
    page_result = client.list_datasets(request=request)
  File "/home/kolban/projects/vertex-ai/datasets/env/lib/python3.7/site-packages/google/cloud/aiplatform_v1/services/dataset_service/client.py", line 1007, in list_datasets
    metadata=metadata,
  File "/home/kolban/projects/vertex-ai/datasets/env/lib/python3.7/site-packages/google/api_core/gapic_v1/method.py", line 113, in __call__
    return wrapped_func(*args, **kwargs)
  File "/home/kolban/projects/vertex-ai/datasets/env/lib/python3.7/site-packages/google/api_core/grpc_helpers.py", line 74, in error_remapped_callable
    raise exceptions.from_grpc_error(exc) from exc
google.api_core.exceptions.MethodNotImplemented: 501 Received http2 header with status: 404

我可能做错了什么?

【问题讨论】:

    标签: google-cloud-vertex-ai


    【解决方案1】:

    将代码更改为以下内容使其工作:

    from google.cloud import aiplatform_v1
    from google.api_core.client_options import ClientOptions
    
    
    def sample_list_datasets():
        service_base_path='aiplatform.googleapis.com'
        region='us-central1'
        client_options = ClientOptions(api_endpoint=f"{region}-{service_base_path}")
        client = aiplatform_v1.DatasetServiceClient(client_options=client_options)
        request = aiplatform_v1.ListDatasetsRequest(
            parent="projects/MYPROJECT/locations/us-central1",
        )
    
        # Make the request
        page_result = client.list_datasets(request=request)
    
        # Handle the response
        for response in page_result:
            print(response)
    
    sample_list_datasets()
    

    在找到 here 的 API 请求的文档中暗示了该解决方案。在那篇文章中有一个代码示例,在代码示例中有一些 cmets,在 cmets 中写了以下内容:

    这是核心线索。当我们进行 Vertex AI 调用时,我们必须指定在哪里请求将被发送。为此,我们将 api_endpoint 选项设置为 [REGION]-aiplatform.googleapis.com 形式的 URL。

    【讨论】:

      猜你喜欢
      • 2021-12-02
      • 2023-02-15
      • 2022-09-27
      • 2022-01-18
      • 1970-01-01
      • 2022-11-10
      • 2022-10-06
      • 2022-01-12
      • 2021-09-21
      相关资源
      最近更新 更多