0

I am new to python, I am upgrading a flask app from python2 to python3 with minimal code changes, but not able to get rid of issue with dictionary and jsonify.

Here 'data' is a dictionary.

   message = {
                'success': True,
                'result': data
        }
        resp = jsonify(message)
        resp.status_code = 200
        return resp

Getting this error ;

TypeError: Object of type 'bytes' is not JSON serializable

Can someone help to get past this.?

tony
  • 71
  • 2

1 Answers1

0

Your data object type is bytes. Json only works with unicode strings. Decoding data should solve your problem

message = {
        'success': True,
        'result': data.decode("utf-8")
}
resp = jsonify(message)
resp.status_code = 200
return resp
ozcnakd
  • 59
  • 2