| 158 | === Why does Genshi raise a `UnicodeDecodeError` when I try to render non-ASCII strings? === |
| 159 | |
| 160 | Genshi refuses to work with bytestrings that do not use the system default encoding, which on most systems is ASCII. This behavior is by design. If you want to render strings that contain characters outside of the ASCII range (or don't use the system default encoding), you will have to pass `unicode` objects to Genshi. |
| 161 | |
| 162 | This doesn't mean that Genshi has bad support for non-ASCII strings. Quite the contrary -- Genshi works beautifully with unicode. It just requires that you do the decoding of your bytestrings before passing the data to the templates. If this data comes from a database, it's likely that your database connector provides an option to automatically decode any data to unicode. SQLAlchemy, for example, provides a `convert_unicode` flag you can specify when [http://www.sqlalchemy.org/docs/dbengine.html#dbengine_options creating an engine]. Set that flag to `True`, and you get rid of a whole class of potentially nasty problems. |
| 163 | |
| 164 | For more information on unicode and using unicode in Python applications, see: |
| 165 | * [http://www.joelonsoftware.com/articles/Unicode.html The Absolute Minimum Every Software Developer Absolutely, Positively Must Know About Unicode and Character Sets (No Excuses!)] by Joel Spolsky |
| 166 | * [http://www.amk.ca/python/howto/unicode Unicode HOWTO] by A.M. Kuchling |
| 167 | * [http://pylonshq.com/docs/0.9.5/internationalization.html#understanding-unicode Internationalization, Localization and Unicode] in the Pylons documentation |
| 168 | |