Thursday, November 12, 2020

REST framework API through Object of type datetime is not JSON serializable error with auth.backends.RemoteUserBackend

Hi All,
migrating existing piston based Django api to REST framework api, it works in dev environment but once moved to QA with django.contrib.auth.backends.RemoteUserBackend enabled in settings, getting the following error

raise TypeError(f'Object of type {o.__class__.__name__} '
TypeError: Object of type datetime is not JSON serializable

To test using the following simple code, once we disable auth.backends.RemoteUserBackend it works

class ApplicationHandler(APIView):
    def get(self, request):
        usernames = [user.username for user in User.objects.all()]
        return Response(usernames)

using Python-3.8 and Django-3.0.3 on RHEL-7, please advice what causes this error and how to resolve it.

thanks,
-bala 

No comments:

Post a Comment