Object of type __proxy__ is not JSON serializable
See original GitHub issueif there is ugettext_lazy, just encounter error ‘Object of type proxy is not JSON serializable’
solved by,
from django.utils.functional import Promise
from django.core.serializers.json import DjangoJSONEncoder
class LazyEncoder(DjangoJSONEncoder):
def default(self, obj):
if isinstance(obj, Promise):
return force_text(obj)
return super(LazyEncoder, self).default(obj)`
data_browser\views.py
...
def query_html(request, *, model_name="", fields=""):
...
config = json.dumps(config, cls=LazyEncoder)
...
Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (6 by maintainers)
Top Results From Across the Web
django - TypeError at /en/ Object of type '__proxy__' is not ...
When using the JSONSerializer for storing data in the session object, that data must only contain values that can be translated to json....
Read more >TypeError: Object of type '__proxy__' is not JSON serializable ...
Its the python json module that doesn't handle lazy objects very well, but inside this module, we need to evaluate it, the entire...
Read more >Object of type is not JSON serializable in Python - LinuxPip
“Object of type is not JSON serializable” is a common error message in Python. It basically says that the built-in json module cannot...
Read more >Django object is not JSON serializable | Edureka Community
Your answer Hello @kartik, simplejson and json don't work with django objects well. In your case, self. get_queryset() contains a mix of django ......
Read more >Object of type 'Product' is not JSON serializable-django
The error you mentioned is raised from json encode default method. That means the json module does not recognize the Product object.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I found the difference there. “.ctx” is using JsonResponse which internally uses the DjangoJSONEncoder which deals with Promise objects. However “.html” is using json.dumps directly and so is getting the standard encoder. So the correct fix is to specify the DjangoJSONEncoder on the json.dumps call, I’ve added that and a test. They will be released as part of 2.2.7, probably in the next day or so.
thanks @tolomea !
['allModelFields', 'base.Company', 'fields', '_type', 'choices', 0, 1] <class 'django.utils.functional.lazy.<locals>.__proxy__'> 付款公司
…