Just a nitpick on this. This is actually a Python "gotcha". You'll notice that the .encode('base64') method actually is a base-64 Content-Transfer-Encoding[1] which enforces a limit on the length of the line to 76 characters. Here's an example demonstrating the difference:
import base64
eighty_chars = ("X" * 80)
assert '\n' in eighty_chars.encode('base64').strip()
assert '\n' not in base64.b64encode(eighty_chars)
Just a nitpick on this. This is actually a Python "gotcha". You'll notice that the .encode('base64') method actually is a base-64 Content-Transfer-Encoding[1] which enforces a limit on the length of the line to 76 characters. Here's an example demonstrating the difference:
[1] http://tools.ietf.org/html/rfc3548#2.1