【问题标题】:grpc request without any request param没有任何请求参数的grpc请求
【发布时间】:2020-11-24 20:31:36
【问题描述】:

我有一个请求类型为的 grpc 服务器:

service AbcService {
 rpc GetInfo(GetInfoRequest) returns (GetInfoResponse) {}
}

message GetInfoRequest {}
message GetInfoResponse {
  string hostname = 3;
}

这是我的客户:

channel = grpc.insecure_channel('test.url:1025')
client = svc_pb2_grpc.AbcServiceStub(channel)

# get response
resp = client.GetInfo

我遇到了客户的问题,因为我无法从它那里得到任何回复。 grpcurl 可以很好地使用: grpcurl -plaintext test.url:1025 AbcService/GetInfo

resp = client.GetInfo 是客户端调用此调用的正确方式吗(不期望任何请求参数)?

【问题讨论】:

    标签: grpc grpc-python


    【解决方案1】:

    “存根”用一个类封装您的服务器,其中不同的 API 调用(请求/响应)是方法调用。

    首先: resp = client.GetInfo()

    但是,GetInfo 需要 GetInfoRequest,因此您需要:

    resp = client.GetInfo(GetInfoRequest())

    【讨论】:

      猜你喜欢
      • 2019-03-18
      • 1970-01-01
      • 1970-01-01
      • 2020-11-10
      • 2021-11-06
      • 2018-04-19
      • 2016-12-09
      • 2021-11-04
      • 2022-06-24
      相关资源
      最近更新 更多