Tuesday, November 19, 2013

Re: Error: XXX is not JSON serializable

Thanks; I'm almost positive. I'll double check. I've worked around the problem by converting first.


On Tue, Nov 19, 2013 at 12:58 PM, tim <timograham@gmail.com> wrote:
Are you sure have the list() cast in the deployed version of the code? Trying to serialize a ValuesListQuerySet directly would give the error you mention since repr() of a ValuesListQuerySet looks like a list.


On Tuesday, November 19, 2013 12:28:11 PM UTC-5, Lee Hinde wrote:
I have an app I'm moving from local dev (mac, python 2.7.2, django 1.5.4) to WebFaction (python 2.7.5.

I'm storing record ids like so:

section_ids = list(sections.values_list('id', flat=True))
request.session['query.section_ids.last'] = section_ids


works fine locally and fails on WF with:

(as an example)

    [10892L, 10891L] is not JSON serializable  

This is the traceback...

File "/home/leedhinde/webapps/myapp/lib/python2.7/django/core/handlers/base.py" in get_response
  187.                 response = middleware_method(request, response)
File "/home/leedhinde/webapps/myapp/lib/python2.7/django/contrib/sessions/middleware.py" in process_response
  38.                     request.session.save()
File "/home/leedhinde/webapps/myapp/lib/python2.7/django/contrib/sessions/backends/db.py" in save
  51.             session_data=self.encode(self._get_session(no_load=must_create)),
File "/home/leedhinde/webapps/myapp/lib/python2.7/django/contrib/sessions/backends/base.py" in encode
  84.         serialized = self.serializer().dumps(session_dict)
File "/home/leedhinde/webapps/myapp/lib/python2.7/django/core/signing.py" in dumps
  100.         return json.dumps(obj, separators=(',', ':')).encode('latin-1')
File "/usr/local/lib/python2.7/json/__init__.py" in dumps
  250.         sort_keys=sort_keys, **kw).encode(obj)
File "/usr/local/lib/python2.7/json/encoder.py" in encode
  207.         chunks = self.iterencode(o, _one_shot=True)
File "/usr/local/lib/python2.7/json/encoder.py" in iterencode
  270.         return _iterencode(o, 0)
File "/usr/local/lib/python2.7/json/encoder.py" in default
  184.         raise TypeError(repr(o) + " is not JSON serializable")


I'm not clear why this wouldn't work. I also haven't figured out testing session updating in the shell for simpler testing.

Any pointers would be appreciated.



--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CA%2BePoMxwJ36WaCcSf5-7ijy2766A3WfG0LrbX%3Dnj6BCi0jGC7w%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate