JSON encoding PDF or Excel files in Python 2.7

Skip Montanaro skip.montanaro at gmail.com
Fri Jul 21 14:52:39 EDT 2017


I would like to JSON encode some PDF and Excel files. I can read the content:

pdf = open("somefile.pdf", "rb").read()

but now what?  json.dumps() insists on treating it as a string to be
interpreted as utf-8, and bytes == str in Python 2.x. I can't
json.dumps() a bytearray. I can pickle the raw content and json.dumps
that, but I can't guarantee the listener at the other end will be
written in Python. Am I going to have to do something like
base64-encode the raw bytes to transmit them?

Thx,

Skip



More information about the Python-list mailing list