[Django]-Jwt.encode fails with "Object of type 'bytes' is not JSON serializable"

1👍

Try importing json, and on your return use json.dumps(response_details):

 return Response(json.dumps(response_details), status=response_details['status'])
👤Drugo

2👍

In older versions of PyJWT like 1.7 decode is required at the end:

jwt.encode(payload, "SECRET_KEY", algorithm='HS256').decode('utf-8')

If you are using the recent versions like 2.3.1 it is not necessary to dump or decode, a string will be generated already in UTF-8

Leave a comment