部分代码:
#接受数据:
print(s.recv(1024).decode('utf-8'))
data=s.recv(1024)
def decode_base64(data):
"""Decode base64, padding being optional.
:param data: Base64 data as an ASCII byte string
:returns: The decoded byte string.
"""
missing_padding = len(data) % 4
if missing_padding != 0:
data += b'='* (4 - missing_padding)
return base64.decode(data.decode(encoding='utf-8'))
print (decode_base64(data))
返回信息:
Input command:2015$201520150527103546679209$B101|9011|0|1019909081|1
MCQkMXwxMDE5OTA5MDgxLOmfqeilv+i/niMsRuWMuue/oOWzsOi3r+S4nOaAoeWSjOWutuWbrTXluaIxMjA15a6kLEhCSDAwLDAzLDAuMDAsMC4wMCwwLjAwLDQ5Ljg4
Traceback (most recent call last):
File "E:\Py\20160809.py", line 36, in <module>
print (decode_base64(data))
File "E:\Py\20160809.py", line 35, in decode_base64
return base64.decode(data.decode(encoding='utf-8'))
TypeError: decode() missing 1 required positional argument: 'output'
使用
base64.b64decode