Python Protobuf Base64消息解码错误

时间:2020-09-09 10:35:22

标签: python flask grpc-python

我正在尝试从后端获取的protobuf base64消息中读取数据。

我的字符串是'AAAAAA8KDQgTEBUgBCjln62lxS6AAAAAD2dycGMtc3RhdHVzOjANCg =='

所以,我在下面创建了原始文件。

syntax = "proto2";

//protoc -I=. --python_out=. ./message.proto

message ArtifactList {
    repeated Artifact artifacts = 1;
    required bool  grpcStatus = 2;
}

message Artifact {
    required string id = 1;
    required string type_id = 2;
    required string uri = 3;
}

生成python proto文件后,我正在使用以下代码。

import message_pb2
import base64

base64_message = 'AAAAAA8KDQgTEBUgBCjln62lxS6AAAAAD2dycGMtc3RhdHVzOjANCg=='
message_bytes = base64.b64decode(base64_message)

artifactList = message_pb2.ArtifactList()
artifactList.ParseFromString(message_bytes)
print(artifactList)

print(message_bytes)

运行此命令时,出现以下错误。我找不到为什么会出现此错误。

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

任何人都可以帮助解决此问题吗?

预先感谢

0 个答案:

没有答案