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")
Answer from Tony Meyer on Stack Overflowencoding - How to base64 encode a PDF file in Python - Stack Overflow
Python API to convert a pdf to Base64 String and POST to an S3 bucket
python - How to convert a pypdf reader object into a base64 string - Stack Overflow
python - How to convert a PDF from base64 string to a file? - Stack Overflow
Q2. How To Use C# To Convert PDF to Base64?
Q1. Can You Convert Any File to Base64?
Q3. Can a PDF Be Converted?
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")
Actually, after some more digging, it looks like the xmlrpclib module may have the piece I need with it's Binary helper class:
binary_obj = xmlrpclib.Binary( open('foo.pdf').read() )
Here's an example from the Trac XML-RPC documentation
import xmlrpclib
server = xmlrpclib.ServerProxy("http://athomas:password@localhost:8080/trunk/login/xmlrpc")
server.wiki.putAttachment('WikiStart/t.py', xmlrpclib.Binary(open('t.py').read()))
From my understanding base64decode only takes in a base64 string and looks like you have some headers on your string that are not encoded.
I would remove "data:application/pdf;base64,"
check out the doc here: https://docs.python.org/2/library/base64.html
When I've used it in the past, I have only used the encoded string.
Does writing it by using the codecs.decode function work?
also as Mark stated, you can try to remove the data:application/pdf;base64, portion of the string as this section of the string is not to be decoded.:
import codecs
base64String = "JVBERi0xLjQKJeHp69MKMSAwIG9iago8PC9Qcm9kdWNlciAoU2tpYS9..."
with open("test.pdf", "wb") as f:
f.write(codecs.decode(base64string, "base64"))