I've done this:-
try: with open(filename,'rb' ) as dat_file: foil = dat_file.read()because my code reads and repairs arbitrary "text" files - in my analysis, some files have mixed line endings (caused by linux/mac people adding lines to DOS files) in the same file, and dozens of other nutty things... anyhow - long story short - I must read the file as binary.
Now, if my repairs fail, I want to send a verbatim copy of what the file is (including all the stuffed up line ends, nulls, messed-up encodings, etc) to my server as JSON in a data post.
Therein lies the problem...
Object of type 'bytes' is not JSON serializableWhat is the trick to putting binary data of no encoding into a JSON string?