【问题标题】:Exception serializing message异常序列化消息
【发布时间】:2020-11-12 01:37:50
【问题描述】:

我在 grpc 中使用如下消息请求流:

def Post(self, request_iterator, context):
        print("Post")
        for request in request_iterator:
            print("Request")
            if hasattr(request , "type"):
                print("Has type")

使用以下原型:

syntax ="proto3";

package nbsb;

message SDF {
    Thing thing = 1;
    repeated Object objects = 2;
    string type = 3;
}

message Property {
    string name = 1;
    string value = 2;
}
message Thing {
    string id = 1;
    string name = 2;
}
message Object {
    repeated string idObject = 1;
    string name = 2;
    repeated Property properties = 3;
}

message Response {
    repeated string id = 1;
    string value = 2;
}

service Connector{
    rpc Get(SDF) returns (Response){}
    rpc Put(SDF) returns (Response){}
    rpc Post(stream SDF) returns (stream SDF){}
}

所需的输出应该是正确的消息序列化和反序列化。输出如下:

Post
<grpc._server._RequestIterator object at 0x000002CA1CFE5100>
ERROR:grpc._common:Exception serializing message!
Traceback (most recent call last):
  File "C:\Python\Python3\lib\site-packages\grpc\_common.py", line 83, in _transform
    return transformer(message)
  File "C:\Python\Python3\lib\site-packages\google\protobuf\internal\python_message.py", line 1082, in SerializeToString
    if not self.IsInitialized():
AttributeError: 'NoneType' object has no attribute 'IsInitialized'

有人可以帮我解决或理解为什么会这样吗?

【问题讨论】:

    标签: python protocol-buffers grpc grpc-python


    【解决方案1】:

    None 似乎是从 gRPC 库返回的,可能存在静默异常。如果你对pdb很熟悉,能不能试着找到None消息的出处?或者,您可以通过指定环境变量GRPC_TRACE=all GRPC_VERBOSITY=debug打开跟踪日志,参见doc

    如果问题仍然存在,请考虑将其报告给https://github.com/grpc/grpc/issues,并附上重现的sn-p。

    【讨论】:

      猜你喜欢
      • 2023-03-17
      • 1970-01-01
      • 2014-10-22
      • 2013-04-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多