[egenix-users] Unicode problems with mxODBCZopeDA-1.0.10

M.-A. Lemburg mal at egenix.com
Tue Nov 27 13:35:25 CET 2007

On 2007-11-27 01:30, Jose Rivera Merla wrote:
> *I am having problems displaying spanish accents like á,é,í,ó and ú.
> My setup is:*
>    - Plone 3.0.3
>    - CMF-2.1.0
>    - Zope (Zope 2.10.5-final, python 2.4.4, win32)
>    - Python 2.4.4 (#71, Oct 18 2006, 08:34:43) [MSC v.1310 32 bit
>    (Intel)]
>    - PIL 1.1.6
> *and mxodbc:*
> mxODBCZopeDA (Installed product mxODBCZopeDA
> (mxODBCZopeDA-1.0.10))<http://fctcmty01:8080/Control_Panel/Products/mxODBCZopeDA/manage_workspace>
> *With the following string returned from a database I get a problem:*
> 'XX a\xe1 e\xe9 i\xed o\xf3 u\xfa A\xc1 E\xc9 I\xcd O\xd3 U\xda n\xf1 N\xd1'
> *When I try to display it it doesn't  display correctly, I made an
> experiment with the same value in a python script and it worked after I
> returned the following script*
> u'XX a\xe1 e\xe9 i\xed o\xf3 u\xfa A\xc1 E\xc9 I\xcd O\xd3 U\xda n\xf1
> N\xd1'
> *instead of just*
> 'XX a\xe1 e\xe9 i\xed o\xf3 u\xfa A\xc1 E\xc9 I\xcd O\xd3 U\xda n\xf1 N\xd1'
> *How can I make it work?

Could you tell us how you are reading the above string, e.g.
which column data type does the table have, are you using
Z SQL Methods to access the data, etc. ?

Also: which database are you using and how exactly does the string
show up in the browser ?

The data in your string appears to be Latin-1 encoded. Prepending
the "u" modifier to the string will have Python interpret it
as Unicode literal and thus have Zope convert the data to whatever
the page you're inserting the string into uses as encoding.

If you try to insert the string as-is into, say, a UTF-8 encoded
page, then the browser will have problems displaying the mixture
of Latin-1 and UTF-8 data.

In such a case, you have to explicitly convert the string data
into UTF-8 before inserting it into the page.

Marc-Andre Lemburg

Professional Python Services directly from the Source  (#1, Nov 27 2007)
>>> Python/Zope Consulting and Support ...        http://www.egenix.com/
>>> mxODBC.Zope.Database.Adapter ...             http://zope.egenix.com/
>>> mxODBC, mxDateTime, mxTextTools ...        http://python.egenix.com/

:::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,MacOSX for free ! ::::

   eGenix.com Software, Skills and Services GmbH  Pastor-Loeh-Str.48
    D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
           Registered at Amtsgericht Duesseldorf: HRB 46611

More information about the egenix-users mailing list