K
K
Kirill Gusarev2021-09-11 10:19:25
Python
Kirill Gusarev, 2021-09-11 10:19:25

Need base64: use codecs module or base64 module?

Hello. Up to this point, to convert b'Strings' to base64, I used the codecs module: codecs.encode(b_string, 'base64') and codecs.decode(b_string_with_base64_encoding, 'base64') and it seemed to work fine. But recently I saw in some docks that the [also standard] base64 module is used for this, and I started testing it and understanding it. To my surprise, codecs and base64 produce different base64 strings for the same line. O_O - codecs adds '\n' to the end of the output string.
Why so? o_o

UPD:
I found a section in Pituhon's docs that says that '\n' is always put at the end when encoding to base64: Convert the operand to multiline MIME base64 (the result always includes a trailing '\n').
Changed in version 3.4:

https://docs.python.org/3/library/codecs.html#bina...
But I still don't understand why.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Saboteur, 2021-09-11
@kaka888

\n does not interfere with coding|decoding. in base64 In general, this character is not involved in the actual transmission of information. For formatting only

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question