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

时间:2018-11-13 11:06:24

标签: 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

1 个答案:

答案 0 :(得分:1)

您可以通过定义为here的环境变量在gRPC中启用调试日志记录。通过设置GRPC_VERBOSITY = DEBUG_GRPC和GRPC_TRACE = http,服务器将在其http2堆栈中打印活动。您将不得不在输出中进行筛选以找到所需的内容。