我只在树莓派接收这些错误:"TypeError: unhashable type: 'bytearray'"
截断的消息由于 “类型错误:unhashable类型: '的bytearray'”(在覆盆子PI)
- 的Python 3.5.3
- Raspbian拉伸9.1
- 下面的包: grpcio(1.6.3) grpcio反射(1.6.3) grpcio工具(1.6.3)
test.proto (很简单):
syntax = "proto3";
package bug;
message Foo
{
string field1 = 1;
}
和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')
反序列化不但不能在树莓派(Ubuntu是罚款):
field1: "AAAA"
Traceback (most recent call last): File "/home/pi/.local/lib/python3.5/site-packages/google/protobuf/internal/python_message.py", line 1069, in MergeFromString if self._InternalParse(serialized, 0, length) != length: File "/home/pi/.local/lib/python3.5/site-packages/google/protobuf/internal/python_message.py", line 1092, in InternalParse field_decoder, field_desc = decoders_by_tag.get(tag_bytes, (None, None)) TypeError: unhashable type: 'bytearray'
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File "test.py", line 13, in foo.ParseFromString(REF) File "/home/pi/.local/lib/python3.5/site-packages/google/protobuf/message.py", line 185, in ParseFromString self.MergeFromString(serialized) File "/home/pi/.local/lib/python3.5/site-packages/google/protobuf/internal/python_message.py", line 1075, in MergeFromString raise message_mod.DecodeError('Truncated message.') google.protobuf.message.DecodeError: Truncated message.