Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/319.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php python:在拦截器中读取grpc proto请求_Php_Python_Protocol Buffers_Grpc - Fatal编程技术网

Php python:在拦截器中读取grpc proto请求

Php python:在拦截器中读取grpc proto请求,php,python,protocol-buffers,grpc,Php,Python,Protocol Buffers,Grpc,如何使用Python在拦截器中读取grpc proto请求 在PHP中,我可以读取$参数,这就是我所需要的 <?php use Grpc\Interceptor; class MyInterceptor extends Interceptor { public function interceptUnaryUnary($method, $argument,

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

在PHP中,我可以读取
$参数
,这就是我所需要的

<?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);
    }
}

不幸的是,gRPC Python没有一个完整的服务器拦截器实现,允许您访问
请求
服务上下文
,但您可以访问
方法
字符串和
调用元数据
,有关更多详细信息,请查看。如果您想要实现的语义可以在Python的元类或继承中实现,请这样做。如果您想请求此功能,请在GitHub repo中发布一个问题

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

我实现了一个小软件包,它提供了一个可以访问请求和上下文的服务器拦截器。它使用内置的
grpc.ServerInterceptor
,只是简化了接口

下面是一个关于如何使用它的简短片段:

类MyInterceptor(ServerInterceptor):
def拦截(自身、方法、请求、上下文、方法名称):
#在这里做些有趣的事情。。。
返回方法(请求、上下文)
中有更完整的示例

它有麻省理工学院的许可证,所以你可以随意使用它。如果您不想使用这个包,而是想看看它是如何工作的,那么代码就是。它是从一个简单的例子改编和简化的