| 1 | xml = serializers.serialize("xml", Anymodel.objects.all())
|
|---|
| 2 |
|
|---|
| 3 | If the model data contains unicode characters the sealize process fails:
|
|---|
| 4 |
|
|---|
| 5 | -------
|
|---|
| 6 | exceptions.UnicodeDecodeError Traceback (most
|
|---|
| 7 | recent call last)
|
|---|
| 8 |
|
|---|
| 9 | /usr/local/lib/python2.4/site-packages/django/core/serializers/
|
|---|
| 10 | __init__.py in serialize(format, queryset, **options)
|
|---|
| 11 | 65 """
|
|---|
| 12 | 66 s = get_serializer(format)()
|
|---|
| 13 | ---> 67 s.serialize(queryset, **options)
|
|---|
| 14 | 68 return s.getvalue()
|
|---|
| 15 | 69
|
|---|
| 16 |
|
|---|
| 17 | /usr/local/lib/python2.4/site-packages/django/core/serializers/base.py
|
|---|
| 18 | in serialize(self, queryset, **options)
|
|---|
| 19 | 38 if field.rel is None:
|
|---|
| 20 | 39 if self.selected_fields is None or
|
|---|
| 21 | field.attname in self.selected_fields:
|
|---|
| 22 | ---> 40 self.handle_field(obj, field)
|
|---|
| 23 | 41 else:
|
|---|
| 24 | 42 if self.selected_fields is None or
|
|---|
| 25 | field.attname[:-3] in self.selected_fields:
|
|---|
| 26 |
|
|---|
| 27 | /usr/local/lib/python2.4/site-packages/django/core/serializers/
|
|---|
| 28 | xml_serializer.py in handle_field(self, obj, field)
|
|---|
| 29 | 70 value = self.get_string_value(obj, field)
|
|---|
| 30 | 71 self.xml.characters(str(value))
|
|---|
| 31 | ---> 72 else:
|
|---|
| 32 | 73 self.xml.addQuickElement("None")
|
|---|
| 33 | 74
|
|---|
| 34 |
|
|---|
| 35 | /usr/lib/python2.4/site-packages/_xmlplus/sax/saxutils.py in
|
|---|
| 36 | characters(self, content)
|
|---|
| 37 | 307
|
|---|
| 38 | 308 def characters(self, content):
|
|---|
| 39 | --> 309 writetext(self._out, content)
|
|---|
| 40 | 310
|
|---|
| 41 | 311 def ignorableWhitespace(self, content):
|
|---|
| 42 |
|
|---|
| 43 | /usr/lib/python2.4/site-packages/_xmlplus/sax/saxutils.py in
|
|---|
| 44 | writetext(stream, text, entities)
|
|---|
| 45 | 186 def writetext(stream, text, entities={}):
|
|---|
| 46 | 187 stream.errors = "xmlcharrefreplace"
|
|---|
| 47 | --> 188 stream.write(escape(text, entities))
|
|---|
| 48 | 189 stream.errors = "strict"
|
|---|
| 49 | 190 else:
|
|---|
| 50 |
|
|---|
| 51 | /usr/lib/python2.4/codecs.py in write(self, object)
|
|---|
| 52 | 176 """ Writes the object's contents encoded to
|
|---|
| 53 | self.stream.
|
|---|
| 54 | 177 """
|
|---|
| 55 | --> 178 data, consumed = self.encode(object, self.errors)
|
|---|
| 56 | 179 self.stream.write(data)
|
|---|
| 57 | 180
|
|---|
| 58 |
|
|---|
| 59 | UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position
|
|---|
| 60 | 54: ordinal not in range(128)
|
|---|
| 61 | ------
|
|---|
| 62 | I'm using version from svn (rev. 4997) and the default charset, utf-8.
|
|---|