diff --git a/lib/py/images/images.py b/lib/py/images/images.py index e4f9ca3d4d..0a9d36f08f 100644 --- a/lib/py/images/images.py +++ b/lib/py/images/images.py @@ -42,6 +42,7 @@ import struct import os import array +import sys from . import magic from . import pb @@ -284,9 +285,15 @@ def dump(self, entries, f): size = len(pb_str) f.write(struct.pack('i', size)) f.write(pb_str) - f.write(base64.decodebytes(str.encode(item['extra']))) + if (sys.version_info > (3, 0)): + f.write(base64.decodebytes(str.encode(item['extra']))) + else: + f.write(base64.decodebytes(item['extra'])) else: - f.write(base64.decodebytes(str.encode(item['extra']))) + if (sys.version_info > (3, 0)): + f.write(base64.decodebytes(str.encode(item['extra']))) + else: + f.write(base64.decodebytes(item['extra'])) def dumps(self, entries): f = io.BytesIO('') diff --git a/lib/py/images/pb2dict.py b/lib/py/images/pb2dict.py index 068d583dc8..cfaff6c7d0 100644 --- a/lib/py/images/pb2dict.py +++ b/lib/py/images/pb2dict.py @@ -3,6 +3,7 @@ import os import quopri import socket +import sys from ipaddress import IPv4Address, IPv6Address, ip_address from google.protobuf.descriptor import FieldDescriptor as FD @@ -246,11 +247,17 @@ def encode_dev(field, value): def encode_base64(value): - return base64.encodebytes(value).decode() + if (sys.version_info > (3, 0)): + return base64.encodebytes(value).decode() + else: + return base64.encodebytes(value) def decode_base64(value): - return base64.decodebytes(str.encode(value)) + if (sys.version_info > (3, 0)): + return base64.decodebytes(str.encode(value)) + else: + return base64.decodebytes(value) def encode_unix(value):