Python 由于“错误”而截断消息;类型错误:不可损坏的类型:';bytearray'&引用;(覆盆子皮)

Python 由于“错误”而截断消息;类型错误:不可损坏的类型:';bytearray'&引用;(覆盆子皮),python,raspberry-pi,arm,protocol-buffers,raspbian,Python,Raspberry Pi,Arm,Protocol Buffers,Raspbian,我只在Raspberry Pis中收到这些错误:“TypeError:unhabable type:'bytearray'” Python 3.5.3 拉斯宾拉伸9.1 以下文件包: grpcio(1.6.3) grpcio反射(1.6.3) grpcio工具(1.6.3) test.proto(非常简单): 以及Python代码: from test_pb2 import Foo EXPECTED = bytearray(b'\n\x04AAAA') foo = Foo() foo.fi

我只在Raspberry Pis中收到这些错误:
“TypeError:unhabable type:'bytearray'”

  • Python 3.5.3
  • 拉斯宾拉伸9.1
  • 以下文件包: grpcio(1.6.3) grpcio反射(1.6.3) grpcio工具(1.6.3)
test.proto(非常简单):

以及Python代码:

from test_pb2 import Foo

EXPECTED = bytearray(b'\n\x04AAAA')
foo = Foo()
foo.field1 = 'AAAA'
print(foo)

data = foo.SerializeToString()
print(data)
assert (data == EXPECTED)

foo.ParseFromString(EXPECTED)
assert (foo.field1 == 'AAAA')
反序列化仅在Raspberry Pi中失败(Ubuntu很好):

字段1:“AAAA”

回溯(最近一次调用上次):文件 “/home/pi/.local/lib/python3.5/site packages/google/protobuf/internal/python_message.py”, 第1069行,在MergeFromString中 if self.\u InternalParse(序列化,0,长度)!=长度:文件“/home/pi/.local/lib/python3.5/site packages/google/protobuf/internal/python_message.py”, 第1092行,内部解析 field_decoder,field_desc=decoders_by_tag.get(tag_bytes,(None,None))类型错误:不可损坏类型:“bytearray”

在处理上述异常期间,发生了另一个异常:

回溯(最近一次调用last):文件“test.py”,第13行,在 foo.ParseFromString(REF)文件“/home/pi/.local/lib/python3.5/site packages/google/protobuf/message.py”, 第185行,在ParseFromString中 self.MergeFromString(序列化)文件“/home/pi/.local/lib/python3.5/site packages/google/protobuf/internal/python_message.py”, 第1075行,在MergeFromString中 raise message_mod.DecodeError(“被截断的消息”).google.protobuf.message.DecodeError:被截断的消息


我设法解决了覆盆子圆周率的问题

问题是,当在Pi中运行时,
bytearray
的反序列化失败,但是,如果数据以
字节的形式传递,则一切正常

因此,我目前的解决办法是:

foo.ParseFromString( bytes(EXPECTED) )
我仍然不知道为什么同样的问题不会发生在台式机上。我注意到,在桌面上调试时,
foo.ParseFromString
显示为
,因此我假设在桌面上有一些在Pi中运行时不可用的本机优化

当我有更多的时间时,我将尝试研究protobuf是如何部署的。也许在此期间,有人可以分享一些细节

foo.ParseFromString( bytes(EXPECTED) )