python - 在 gRPC 转码中允许重复字段

标签 python google-cloud-platform protocol-buffers google-cloud-endpoints grpc-python

我在 Google CLoud Endpoints 中使用 gRPC 我正在为 endpoint python 使用快速示例
我为 SayHelloRepeated 添加了一个函数,但不知道如何转码重复字段。

helloworld.proto

service Greeter {
...

rpc SayHelloRepeated (RepeatedHello) returns (HelloReply) {}

...
}

message RepeatedHello {
repeated HelloRequest hello_request = 1;
}

message HelloRequest {
string name = 1;
}

api_config_http.yaml

http:
rules:
    ...

    - selector: helloworld.Greeter.SayHelloRepeated
    get: /v1/rsayhello/{hello_request}

    ...

当我尝试部署 api_config_http.yaml 时出现错误 Repeated field not allowed

ERROR: (gcloud.endpoints.services.deploy) INVALID_ARGUMENT: Cannot convert to service config.

kind: ERROR message: "http: repeated field not allowed: reached via \'hello_request\' on message \'helloworld.RepeatedHello\'."

更新

如果 HelloRequest 有多个字段,而不仅仅是一个 name 字段,该怎么办。

message HelloRequest {
string name = 1;
string message = 2;
}

最佳答案

根据官方文档Package google.api :

Each mapping specifies a URL path template and an HTTP method. The path template may refer to one or more fields in the gRPC request message, as long as each field is a non-repeated field with a primitive (non-message) type.

这意味着您不能在 gRPC 中使用重复字段。因此,您不能使用这种确切的格式来使用重复的字段。

我建议您查看文档的这一部分 - gRPC Transcoding - 获取有关如何执行解决方法以实现重复字段使用的更多信息。

如果这些信息对您有帮助,请告诉我!

关于python - 在 gRPC 转码中允许重复字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60584941/

相关文章:

python - 在 Python 3 中实例化具有未知数量属性的类的实例

python - sqlalchemy中执行之前如何知道sql查询结果的类型

google-cloud-platform - 如何使用 pubsub 在死信订阅中自动分配发布者角色和订阅者角色?

python - 自动上传训练数据标签 csv 和训练处理 AutoML Vision 图像分类中的模型

sockets - Netty Detect传入请求是protobuf类型

python - 在Python中反序列化Prometheus `remote_write` Protobuf输出

python - 如何在 Windows 上使用 Python 的 Protocol Buffer ?

python 文本到十六进制并搜索十六进制数据或将所有内容转换为二进制

python - pip安装在docker容器中不起作用

google-cloud-platform - Google Stackdriver Logging 在 Google Cloud Shell 和 GKE 中不起作用