python - 异常序列化消息
问题描述
我在 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'
有人可以帮我解决或理解为什么会这样吗?
解决方案
它似乎None
是从 gRPC 库返回的,可能存在静默异常。如果你熟悉pdb
,你能尝试找到None
消息的来源吗?或者,您可以通过指定环境变量打开跟踪日志GRPC_TRACE=all GRPC_VERBOSITY=debug
,请参阅文档。
如果问题仍然存在,请考虑将其报告给https://github.com/grpc/grpc/issues并附上复制片段。
推荐阅读
- r - 提取列表中数据帧的名称传递给 R 中的函数
- android - 检查 PIP 是否处于活动状态
- url - 图片的URI不正确
- vba - 仅从激活的幻灯片中删除动画
- scala - 当条目较少时,将 json 转换为“scala.collection.immutable.HashMap”时出现 ClassCastException
- android-room - 迁移到androidx后没有下载数据
- python - 无法关闭 xlsxwriter 中的工作表
- flutter - Flutter 中 ListView 项的动态高度
- elasticsearch - 在索引上检测到特定数量的分片时发出警报
- javascript - 如何使用 framer x 创建功能推送通知(在 x 时间后触发)组件?