Hi all,<br><br>Due to project demands I had to convert the html entities in all TEXT fields in my database to the real international characters like "ב", "ח" and so on. <br><br>The problem is that all my dynamic generated XML started to fail with UnicodeDecodeError. The XML encoding is set to utf-8 and the file itself is correctly encoded.
<br><br>If I inject the international characters using a Python Script with something like u'חבי' it works, but passing the TEXT field from the database generates the error.<br><br>I'm using Zope 2.9.2 and MySQL. The XML is generated using ZPT.
<br><br>The XML, invokes a script to filter and add links to the text retrieved from the database, ex:<br><br><?xml version='1.0' encoding='utf-8'?><br>... xml stuff ...<br> <txt tal:content="structure python:
container.scripts.montarCDATA(texto=obra.Conteudo, links=obra.links)"></txt><br> <rdp tal:content="structure python:container.scripts.montarCDATA(texto=obra.Rodape)"></rdp><br>
... xml stuff ...<br><br>obra is the database row and Conteudo is the TEXT field.<br><br>montarCDATA is as simple as (I removed the code to build the links):<br>return '<![CDATA[%s]]>' % texto<br><br>if instead of the TEXT field I put something like:
<br>return '<![CDATA[%s]]>' % u'חביא'<br><br>it works, which leads me to believe the problem is with the database field and XML. The strange thing is that with common html everything works as expected.<br><br><p>Traceback (innermost last):
</p><ul><li> Module ZPublisher.Publish, line 115, in publish</li><li> Module ZPublisher.mapply, line 88, in mapply</li><li> Module ZPublisher.Publish, line 41, in call_object</li><li> Module Shared.DC.Scripts.Bindings
, line 311, in __call__</li><li> Module Shared.DC.Scripts.Bindings, line 348, in _bindAndExec</li><li> Module Products.PageTemplates.ZopePageTemplate, line 256, in _exec</li><li> Module Products.PageTemplates.PageTemplate
, line 105, in pt_render<br>
<b><ZopePageTemplate at /path/to/file/ano.xml></b></li><li> Module StringIO, line 271, in getvalue</li></ul>UnicodeDecodeError: 'ascii' codec can't decode byte 0xe1 in position 50: ordinal not in range(128)<br><br>
Thanks in advance,<br clear="all"><br>-- <br>Luiz Fernando B. Ribeiro