You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

调用Vertex AI API时遇StatusCode.UNIMPLEMENTED错误求排查

排查Vertex AI API调用404/501错误的常见原因

我编写了一个简单的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

可能的错误点排查:

  • 替换占位符项目ID:代码中的MYPROJECT是占位符,必须替换为你实际的Google Cloud项目ID,这是最容易忽略的问题。
  • 核对区域信息:确认你的Vertex AI数据集所在区域确实是us-central1,如果数据集部署在其他区域(如europe-west1),需要同步修改parent参数中的区域值。
  • 检查API启用状态:登录Google Cloud控制台,确认Vertex AI API已经被启用,未启用的API会直接返回404错误。
  • 验证本地认证配置:本地运行代码时,确保已经通过gcloud auth application-default login完成身份认证,或者正确设置了服务账号密钥的环境变量GOOGLE_APPLICATION_CREDENTIALS。
  • 更新依赖包版本:google-cloud-aiplatform包的旧版本可能存在兼容性问题,执行pip install --upgrade google-cloud-aiplatform更新到最新稳定版后重试。

内容的提问来源于stack exchange,提问作者Kolban

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.03 13:10:24