How to base64 encode a PDF file in Python

Pat Notz picture Pat Notz · Oct 16, 2008 · Viewed 24.6k times · Source

How should I base64 encode a PDF file for transport over XML-RPC in Python?

Answer

Tony Meyer picture Tony Meyer · Oct 17, 2008

If you don't want to use the xmlrpclib's Binary class, you can just use the .encode() method of strings:

a = open("pdf_reference.pdf", "rb").read().encode("base64")