On Tue, Nov 17, 2009 at 3:34 PM, dfolland <doug.foll...@gmail.com> wrote:

> I've dealt with this by manipulating the data with Python codecs.
>
> import codecs
>
> new_value= codecs.decode(current_value, 'utf-8', 'ignore')
>
> the default option is 'strict' which will raise a ValueError that
> you've experienced, 'ignore' will drop the offending character, and
> 'replace' allows you to replace the malformed data with a suitable
> replacement marker.
>
> sometimes I use a try/except like this
>
> try:
>    new_value= u"%s" % current_value
> except:
>    import codecs
>    new_value= codecs.decode(current_value, 'utf-8', 'ignore')
>
>
This would have not work in this case. My current_value is not malformed or
mistyped data; it is a proper python unicode string. Attempting to parse it
as UTF-8 like this would generate a UnicodeEncodeError - even setting errors
to 'ignore'.

Cheers

Tom

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=.


Reply via email to