如何从 python gRPC 客户端访问尾随元数据
How to access trailing metadata from python gRPC client
这是我从服务器发送元数据的方式。
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'。我想知道在客户端访问尾随元数据的方法。
很抱歉 we don't yet have an example illustrating metadata but you can see here how getting the trailing metadata on the invocation side requires using with_call
(or future
, but that may change the control flow in a way that you don't want changed, so I think that with_call
应该是您的首选)。我认为您的调用端代码应该类似于
response, call = _stub.DoSomething.with_call(request)
print(call.trailing_metadata())
.
这是我从服务器发送元数据的方式。
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'。我想知道在客户端访问尾随元数据的方法。
很抱歉 we don't yet have an example illustrating metadata but you can see here how getting the trailing metadata on the invocation side requires using with_call
(or future
, but that may change the control flow in a way that you don't want changed, so I think that with_call
应该是您的首选)。我认为您的调用端代码应该类似于
response, call = _stub.DoSomething.with_call(request)
print(call.trailing_metadata())
.