Exempting Blobs from JSON

33 views
Skip to first unread message

uo

unread,
Jun 3, 2010, 11:16:48 AM6/3/10
to Google App Engine
Hello people,
I'm developing an app on GAE using Django and I run into a
problem. I'm trying to return json to the front end and the serializer
is trying to serialize binary content in the form of a PNG,
consequently I get this error:

Traceback: File "/media/disk/Projex/propertyPortal/prop/views/item.py"
in json 42. return HttpResponse(simplejson.dumps({"items":[to_dict(i)
for i in Item.all()]}), mimetype='application/json') File "/usr/lib/
python2.6/json/init.py" in dumps 230. return
_default_encoder.encode(obj) File "/usr/lib/python2.6/json/encoder.py"
in encode 367. chunks = list(self.iterencode(o)) File "/usr/lib/
python2.6/json/encoder.py" in _iterencode 309. for chunk in
self._iterencode_dict(o, markers): File "/usr/lib/python2.6/json/
encoder.py" in _iterencode_dict 275. for chunk in
self._iterencode(value, markers): File "/usr/lib/python2.6/json/
encoder.py" in _iterencode 306. for chunk in self._iterencode_list(o,
markers): File "/usr/lib/python2.6/json/encoder.py" in
_iterencode_list 204. for chunk in self._iterencode(value, markers):
File "/usr/lib/python2.6/json/encoder.py" in _iterencode 309. for
chunk in self._iterencode_dict(o, markers): File "/usr/lib/python2.6/
json/encoder.py" in _iterencode_dict 275. for chunk in
self._iterencode(value, markers): File "/usr/lib/python2.6/json/
encoder.py" in _iterencode 294. yield encoder(o) File "/usr/lib/
python2.6/json/encoder.py" in py_encode_basestring_ascii 63. s =
s.decode('utf-8') File "/usr/lib/python2.6/encodings/utf_8.py" in
decode 16. return codecs.utf_8_decode(input, errors, True)

Exception Type: UnicodeDecodeError at /property/json/ Exception Value:
'utf8' codec can't decode byte 0x89 in position 0: unexpected code
byte

my model:

class Item(db.Model): owner = db.UserProperty() title =
db.StringProperty(multiline=True) price = db.StringProperty()
primaryImage = db.BlobProperty()

My question is how can I exclude the image from being serialized to
json? Please help . Thanks

uo

unread,
Jun 3, 2010, 11:18:33 AM6/3/10
to Google App Engine
I did a temporary hack... I edited encoder.py and changed s =
s.decode('utf8') to s = s.decode('utf-8','ignore') and it works.. but
Im not sure it will work on the google servers. . Any advice ? – yonny
18 mins ago
Reply all
Reply to author
Forward
0 new messages