Base64 encoding includes:
>>> 'a'.encode('base64') 'YQ==\n'
Other Base64 encoding methods also include this new line; see base64.encode() , for example:
encode() returns encoded data plus the trailing newline character ( '\n' ).
The choice seems historic; Base64 MIME transmission encoding determines that the maximum line length is used, and new lines are inserted to maintain this length, but RFC 3548 states that it should not be implemented.
Python offers both options; you can use base64.b64encode() function here:
>>> import base64 >>> base64.b64encode('a') 'YQ=='
source share