Processing of b' in front of characters after base64 encoding

After base64 encoding the data in the file, it is found that the encoded self-nothing is in b'.....'

code show as below:

import base64
f = open('1.txt','r',encoding='gbk', errors='ignore')
for line in f:
    t=line.strip()
    A = base64.b64encode(t.encode(encoding='utf8'))
    print(A)

The result is as follows:

b'MQ=='
b'Mg=='
b'Mw=='
b'NA == '
b'NQ == '
b'Ng=='
b'Njc = '

The solution is as follows:

import base64
f = open('1.txt','r',encoding='gbk', errors='ignore')
for line in f:
    t=line.strip()
    A = base64.b64encode(t.encode(encoding='utf8'))
    print(str(A,'utf8')) //Add this to convert the characters
# print(A.decode('ascii')) //You can also use ascii encoding

The effect is as follows:

SQM ==
Mg==
Mw==
NA ==
NQ ==
Ng ==





Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324838444&siteId=291194637