首页 > 解决方案 > python:在拦截器中读取 grpc proto 请求

问题描述

如何使用 Python 在拦截器中读取 grpc proto 请求?

在 PHP 中,我可以阅读$argument,这是我需要的。

<?php

use Grpc\Interceptor;

class MyInterceptor extends Interceptor
{


    public function interceptUnaryUnary($method,
                                        $argument,
                                        $deserialize,
                                        array $metadata = [],
                                        array $options = [],
                                        $continuation)
    {
        // $argument is what I needto 
        return parent::interceptUnaryUnary($method, $argument, $deserialize, $metadata, $options, $continuation);
    }
}

标签: phppythonprotocol-buffersgrpc

解决方案


不幸的是,gRPC Python 没有完整的服务器拦截器实现,允许您访问requestor servicer_context,但您可以访问methodstring 并且invocation_metadata,有关更多详细信息,请查看history。如果您想要实现的语义可以在 Python 的元类或继承中实现,请这样做。如果您想请求此功能,请在 GitHub存储库grpc/grpc中发布问题...

以下是一些可以帮助您找到答案的资源:


推荐阅读