gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 04:16:51 25 4
gpt4 key购买 nike

我在 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com