I have the following code excerpt:
my_response = my_func(
plaintext='my data'.encode()))
)
This throws a TypeError: Object of type bytes is not JSON serializable exception, also, if I change this to:
my_response = my_func(
json.dumps(dict(plaintext='my data'.encode()))
)
I get:
TypeError: cannot convert dictionary update sequence element #0 to a sequence
Can someone please advice as to how I can fix this, I’m using Python 3 BTW
Also, the argument I pass into my_func needs to be base64 encoded, but in text form.
2
Answers
I eventually managed to get the following code to do what I wanted:
The problem is plainly calling the
.encode()
method. This returns a byte string, which you should not force JSON serialize. So, you need to use thedecode
method to "undo" or "reverse" this. Try this:Hope this answers your problem and helps you.