question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Object of type __proxy__ is not JSON serializable

See original GitHub issue

if 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:closed
  • Created 3 years ago
  • Comments:8 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
tolomeacommented, Aug 22, 2020

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.

0reactions
ghiewacommented, Aug 21, 2020

find_bad_value(config)

thanks @tolomea !

  1. changed html to ctx, there is NO gettext_lazy there
  2. following your code, it display message ['allModelFields', 'base.Company', 'fields', '_type', 'choices', 0, 1] <class 'django.utils.functional.lazy.<locals>.__proxy__'> 付款公司
Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found