Eu tenho um arquivo protobuf como abaixo.
syntax = "proto3";
message Message {
repeated bytes data = 1;
}
Este é o código Python.
import test_pb2
message = test_pb2.Message()
with open("test.dat", mode='rb') as file:
message.data.extend(file.read())
Este é o erro.
Traceback (most recent call last):
File "./test.py", line 7, in <module>
message.data.extend(file.read())
TypeError: 48 has type int, but expected one of: bytes
Também tento "read_bytes ()", erro semelhante.
O código a seguir funciona bem.
x = list()
with open("test.dat", mode='rb') as file:
x.extend(file.read())
Aparentemente, o objeto repetido não funciona como uma lista.
Tentar:
file.read()
retornabytes
, mas você precisaIterable[bytes]