在 Python 中打印完整的 HTTP/2 gRPC 响应

M20*_*M20 1 python http protocol-buffers grpc

我有一个 Python 中的 gRPC 服务器,我正在寻找一种方法来打印它在收到请求后提供的完整 HTTP/2 响应。下面是接收请求并返回响应的方法。

@inject.params(storage='storage')
def getPerson(self, request,context=None, storage = None)
    logger.info('call of username {}'.format(
        request.username
    ))
    logger.info('Client Metadata {} '.format(
        context.invocation_metadata()
    ))

    response = mProto.Auth()
    response.value = 100
    logger.info('Client Metadata {} '.format(
        context.invocation_metadata()
    ))
    #some code
    response = storage.request(request.username, request.password)
    return response
Run Code Online (Sandbox Code Playgroud)

小智 6

您可以通过此处定义的环境变量在 gRPC 中启用调试日志记录。通过设置GRPC_VERBOSITY=DEBUGGRPC_TRACE=http,服务器将打印其 http2 堆栈中的活动。您必须筛选输出才能找到您想要的内容。