【问题标题】:How to access trailing metadata from python gRPC client如何从 python gRPC 客户端访问尾随元数据
【发布时间】:2017-09-09 00:28:01
【问题描述】:

这是我从服务器发送元数据的方式。

def DoSomething(self, request, context):
    response = detection2g_pb2.SomeResponse()
    response.message = 'done'
    _SERVER_TRAILING_METADATA = (
                                ('method_status', '1010'),
                                    ('error', 'No Error')
                                )
    context.set_trailing_metadata(_SERVER_TRAILING_METADATA)

    return response

这是我尝试过的:

res = _stub.DoSomething(req) 
    print (res.trailing_metadata()) 

在这种情况下,我得到属性错误对象没有属性'trailing_metadata'。我想知道在客户端访问尾随元数据的方法。

【问题讨论】:

  • 与您的问题无关,但当患者在桌子上时:我认为您应该写 response = detection2g_pb2.SomeResponse(message='done') 而不是您当前代码中的单独构造和变异语句。然后也可以通过写 return detection2g_pb2.SomeResponse(message='done')? 来省略本地字段
  • 有道理。谢谢

标签: grpc


【解决方案1】:

我很抱歉 we don't yet have an example illustrating metadata 但你可以看到 here how getting the trailing metadata on the invocation side requires using with_call(或 future,但这可能会以你不想改变的方式改变控制流,所以我认为 with_call 应该是你的第一选择)。我认为你的调用端代码应该是这样的

response, call = _stub.DoSomething.with_call(request) 
print(call.trailing_metadata())

.

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-03
    • 2020-07-02
    • 2020-10-15
    • 2017-09-14
    • 1970-01-01
    相关资源
    最近更新 更多