Je reçois ces erreurs que dans Raspberry Pi: "TypeError: unhashable type: 'bytearray'"
TRONQUE message en raison de "TypeError: Type unhashable: 'bytearray'" (en pi framboise)
- Python 3.5.3
- Raspbian extensible 9.1
- Les paquets suivants: grpcio (1.6.3) grpcio-réflexion (1.6.3) grpcio-outils (1.6.3)
test.proto (Très simple):
syntax = "proto3";
package bug;
message Foo
{
string field1 = 1;
}
et le code 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')
Le désérialisation échoue seulement Raspberry Pi (Ubuntu est très bien):
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.