python - 在 Python 服务器中读取 gRPC 元数据

标签 python grpc

我有这样的客户:

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/

相关文章:

go - 生成 Golang grpc + 自定义 proto 对象

python - 如何在django-tables2 Column中使用用户权限

python - 类实例中的上下文管理器

microservices - grpc 给出 "INTERNAL: Connection closed with unknown cause"

protocol-buffers - gRPC 的示例不起作用

java - stub 的 gRPC 并发

python - 非 ASCII 字符 '\x90' 在 vi​​rtualenv 中的 windows 上执行 pserve

python - Integrate.ode 设置的 t0 值超出了我的数据范围

python - 将 Pandas-Dataframe 从横截面数据重新排列为面板数据

go - 使用 gRPC : how to get the size of the client-side buffer? 的无缓冲双向数据流