我有这样的客户:
def run():
channel = grpc.insecure_channel('localhost:50051')
stub = helloworld_pb2_grpc.GreeterStub(channel)
metadata = [('key', "value")]
response = stub.SayHello(
helloworld_pb2.HelloRequest(name='you'),
metadata=metadata
)
print("Greeter client received: " + response.message)
和服务器:
class Greeter(helloworld_pb2_grpc.GreeterServicer):
def SayHello(self, request, context):
return helloworld_pb2.HelloReply(message='Hello, %s!' % request.name)
那么,在服务器端,我该如何读取客户端发送的元数据呢?
最佳答案
https://grpc.io/grpc/python/grpc.html#grpc.ServicerContext.invocation_metadata
我们可以使用context.invocation_metadata()
来访问客户端的元数据
关于python - 在 Python 服务器中读取 gRPC 元数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49553534/