[mod_python] encoding

Julien Cigar jcigar at ulb.ac.be
Mon Aug 28 11:12:21 EDT 2006


I have a little question about encodings.
On the project I'm currently working on, everything is in unicode :
- locales on the server (LANG=en_US.UTF-8)
- the PostgreSQL database
- ...

I'm using the Psycopg2 module to interact with PostgreSQL, and SimpleTAL 
for the template engine.
Those two libraries requires type unicode instead of type str, otherwise 
I get errors (ContextContentException: Found non-unicode string in 
Context! for SimpleTal, and a "Can't adapt ...." error with psycopg2). 
It's still a little obscure for me why it doesn't work with type str ...

The solution I found (which works) was to .decode('utf-8') or 
unicode(mystr, 'utf-8') the POSTed data, but I wondered if it's not 
dangerous or incorrect to do like that ? To my knowledge, Apache does 
not make conversion of encoding, so it should be done at the mod_python 
level, right ?

Is there a cleaner solution, which works in all cases ?

In advance thanks, and sorry for my English

Julien Cigar
Belgian Biodiversity Platform
Université Libre de Bruxelles
Campus de la Plaine CP 257
Bâtiment NO, Bureau 4 N4 115C (Niveau 4)
Boulevard du Triomphe, entrée ULB 2
B-1050 Bruxelles
office: jcigar at ulb.ac.be
home: mage at mordor.ath.cx

More information about the Mod_python mailing list