Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 23131

Python - how to overcome Object of type 'bytes' is not JSON serializable in order to put binary data into JSON

$
0
0

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 serializable

What is the trick to putting binary data of no encoding into a JSON string?


Viewing all articles
Browse latest Browse all 23131

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>