Unicode to Ascii Conversion
It's not just once that I stumbled upon this error when trying to work with strings that have special characters (é, etx.):
- UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 1: ordinal not in range(128)
Here's what I found to fix this:
- from django.utils.encoding import force_unicode
- html = force_unicode(str)
- html = html.encode('ascii', 'xmlcharrefreplace')
This way, the special characters are transformed in html friendly version (é etx.).
http://www.amk.ca/python/howto/unicode



Discussion
Excellent Post, nice trick
I keep reading your posts.
Leave a Comment :
Leave a Comment