Protobuf RuntimeWarning:意外的端组标签未转换所有数据

问题描述 投票:0回答:2

我有这个 utf-8 编码文件,我需要从中收集 protobuf 可行的十六进制转储,然后将其提供给 protobuf。.proto 文件按预期工作,生活几乎完美。

message_content = message_content.replace(" ","")
message_content = binascii.unhexlify(message_content)

我将字符串转换为原始字节,然后将其输入到 protobuf

msg.ParseFromString(message_content)

由此导致错误

 RuntimeWarning: Unexpected end-group tag: Not all data was converted
 msg.ParseFromString(message_content)

我无法判断我的十六进制部分是否收集得不好或者是否已损坏。 message_content 看起来像这样:

b"87\x00\x00C\x17\x11\x10j\x17\x11\x10\x0c\x00\xc2\x00\x08\xec\xad\xe8\xe0\xf9\x04\x10\x01\x1a\x1f\x08\xea\xae\x18\x12\x14\x01\x00\x0f\x00\x02\x02|\xf0%\x00\x01&\x00\x01'\x00\x01*\x00\x01*\x01\x00\x1a\x00\x1a \x08\xea\xae\x14\x12\x14\x01\x00\x0f\x00\x02\x02|\xf0%\x00\x01&\x00\x01'\x00\x01(\x00\x01*\x02\x00\x00\x1a\x00\x1a#\x08\xea.\x12\x14\x01\x00\x0f\x00\x02\x02|\xf0%\x00\x01&\x00\x011\x00\x012\x00\x01*\x06\x00\x00\x00\x00\x00\x00\x1a\x00\x1a \x08\xea\xae\x14\x12\x14\x01\x00\x0f\x00\x02\x02|\xf0%\x00\x01&\x00\x01'\x00\x01(\x00\x02*\x02\x00\x00\x1a\x00\x1a\x1d\x08\xea\xae\x0c\x12\x11\x01\x00\x0f\x00\x02\x02|\xf0%\x00\x01&\x00\x011\x00\x01*\x02\x00\x00\x1a\x00"
python-3.x serialization protocol-buffers
2个回答
0
投票

我也有类似的问题。最后发现上游源提供的数据有问题。也可以检查一下base64数据源是否有问题


0
投票

我遇到了同样的错误。

错误代码是:

rsp_serialize =  base64.b64decode(str(rsp)) 
item_info = StrucItem()
item_info.ParseFromString(rsp_serialize)

正确的代码是:

rsp_serialize =  base64.b64decode(str(rsp, encoding="utf-8")) 
item_info = StrucItem()
item_info.ParseFromString(rsp_serialize)

所以你应该检查你的上游数据是否正常?

© www.soinside.com 2019 - 2024. All rights reserved.