我有一组base64编码的字符串。当我尝试解码相同的内容时,解码的文本只有实际字符串的最后一行。在任何在线base64解码器上,都会显示整个文本。在解码之前,我尝试过将文本编码为utf-8和不编码为utf-8。 这是我的密码:
import base64
encodedStr = "QXJyaXZhbCBNZXNzYWdlDURhdGUgKFVUQyk6IDI2SlVMMjAN"
#with encoding
encodedstr_bytes = encodedStr.encode('utf-8')
decodedBytes = base64.b64decode(encodedstr_bytes)
decodedStr = decodedBytes.decode('utf8')
print(decodedStr)
#without encoding
decodedBytes = base64.b64decode(encodedStr)
decodedStr = decodedBytes.decode("utf-8")
print(decodedStr)
Output :
Date (UTC): 26JUL20
Date (UTC): 26JUL20
Required Output :
Arrival Message
Date (UTC): 26JUL20
字符串有回车符(“\r”),但没有换行符(“\n”)。在Windows上,这会指示打印机返回到行首并覆盖其中的内容。以下代码的行为相同:
相关问题 更多 >
编程相关推荐