Situation:
Attempting to deserialize a django 1.5 queryset
from django.core import serializers
queryset = MyModel.objects.all()
data = serializers.serialize('json', queryset)
#... on another server, data loaded using urllib2:
obj = serializers.deserialize('json', data) # error
Problem:
Django returns the error "string indices must be integers"
Solution:
You are not deserializing what you think you are deserializing. Look at the JSON string and it should be apparent. I had this problem in two cases:
- I had accidentally serialized twice (the JSON string contained escaped quotation marks: \")
- There was an error message instead of the actual object
References:
No comments:
Post a Comment