django-rest-framework-mongoengine
django-rest-framework-mongoengine copied to clipboard
Object of type ObjectId is not JSON serializable
Hi,
While using the django restframework generics.ListCreateAPIView, I am getting below issue for a simple mongodb document, I am getting below error.
TypeError: Object of type ObjectId is not JSON serializable
I am using below versions, django-rest-framework-mongoengine 3.4.1 djangorestframework 3.14.0 Django 3.2.6
Please help and guide further.
Here is the exception stacktrace for reference.
Traceback (most recent call last): File "C:\venvs\ttap\lib\site-packages\django\core\handlers\exception.py", line 47, in inner response = get_response(request) File "C:\venvs\ttap\lib\site-packages\django\core\handlers\base.py", line 204, in get_response response = response.render() File "C:\venvs\ttap\lib\site-packages\django\template\response.py", line 105, in render self.content = self.rendered_content File "C:\venvs\ttap\lib\site-packages\rest_framework\response.py", line 70, in rendered_content ret = renderer.render(self.data, accepted_media_type, context) File "C:\venvs\ttap\lib\site-packages\rest_framework\renderers.py", line 99, in render ret = json.dumps( File "C:\venvs\ttap\lib\site-packages\rest_framework\utils\json.py", line 25, in dumps return json.dumps(*args, **kwargs) File "C:\tz_apps\mnc\lib\json_init.py", line 234, in dumps return cls( File "C:\tz_apps\mnc\lib\json\encoder.py", line 199, in encode chunks = self.iterencode(o, _one_shot=True) File "C:\tz_apps\mnc\lib\json\encoder.py", line 257, in iterencode return _iterencode(o, 0) File "C:\venvs\ttap\lib\site-packages\rest_framework\utils\encoders.py", line 67, in default return super().default(obj) File "C:\tz_apps\mnc\lib\json\encoder.py", line 179, in default raise TypeError(f'Object of type {o.class.name} ' TypeError: Object of type ObjectId is not JSON serializable
这是来自QQ邮箱的假期自动回复邮件。 您好,我最近正在休假中,无法亲自回复您的邮件。我将在假期结束后,尽快给您回复。
For additional details, This issue happens intermittently, and requires the machine restart to solve.