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

更新gcloud与buf后部署Cloud Endpoints遇Timestamp解析错误

解决gcloud endpoints部署时"Unresolved type '.google.protobuf.Timestamp'"错误

问题背景

更新gcloud CLI和buf工具后,执行以下部署命令时出现类型解析错误:

gcloud endpoints services deploy \
    msh-common-proto/release/api_descriptor.pb \
    .deploy/api_config.yaml \
    --no-user-output-enabled

错误信息:

ERROR: (gcloud.endpoints.services.deploy) INVALID_ARGUMENT: Cannot convert to service config.
 'location: "unknown location"
kind: ERROR
message: "Unresolved type \'.google.protobuf.Timestamp\'"
...

未修改业务代码,更新Python Google包后问题仍存在,当前环境版本:

GCLOUD
Google Cloud SDK 468.0.0
alpha 2024.03.08
beta 2024.03.08
bq 2.0.101
cloud-build-local 0.5.2
core 2024.03.08
gsutil 5.27

Python 3.11.7
protobuf==4.24.4

macOS version 12.6.7

解决方案

1. 检查Proto文件的导入声明

确保所有使用Timestamp类型的proto文件中,都显式导入标准定义:

import "google/protobuf/timestamp.proto";

并正确使用类型(例如google.protobuf.Timestamp或.google.protobuf.Timestamp,取决于你的proto包结构)。

2. 重新生成包含完整依赖的api_descriptor.pb

错误核心是生成的api_descriptor.pb未包含google.protobuf.Timestamp的定义,需要调整生成命令确保引入所有依赖:

若使用buf工具:

  • 确保buf.yaml中添加googleapis依赖:
    version: v1
    name: buf.build/your-namespace/your-proto-repo
    dependencies:
      - buf.build/googleapis/googleapis
    
  • 运行buf mod update拉取依赖,然后重新构建descriptor文件:
    buf build --output msh-common-proto/release/api_descriptor.pb
    

若使用protoc:

  • 命令中需指定googleapis的路径,并添加--include_imports参数:
    protoc --include_imports --descriptor_set_out=msh-common-proto/release/api_descriptor.pb \
      -I. -I./path/to/googleapis \
      ./your-proto-files/*.proto
    
    (注:./path/to/googleapis需替换为本地googleapis仓库路径,可通过git clone https://github.com/googleapis/googleapis.git获取)

3. 调整Protobuf版本兼容性

gcloud CLI可能对高版本Protobuf生成的文件兼容性不佳,尝试降级Python Protobuf版本:

pip install protobuf==3.20.3

若需保留4.x版本,使用gcloud内置的protoc重新生成文件:

gcloud components install protoc
protoc --include_imports --descriptor_set_out=api_descriptor.pb ...

4. 验证生成的descriptor文件

通过以下命令检查api_descriptor.pb是否包含Timestamp定义:

protoc --decode google.protobuf.FileDescriptorSet msh-common-proto/release/api_descriptor.pb | grep -A 10 "google/protobuf/timestamp.proto"

若输出包含该文件的定义,说明生成正确;否则需重新检查生成命令。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.27 01:07:03