exceptions with python unicode encode/decode functions (why doesn't errors=ignore actually ignore th

Posted by gatoatigrado on Stack Overflow See other posts from Stack Overflow or by gatoatigrado
Published on 2010-04-21T02:30:03Z Indexed on 2010/04/21 2:33 UTC
Read the original article Hit count: 358

Filed under:
|
|

Does anyone know why the string conversion functions throw exceptions when errors="ignore" is passed? How can I convert from regular Python string objects to unicode without errors being thrown? Thanks very much!

python -c "import codecs; codecs.open('tmp', 'wb', encoding='utf8', errors='ignore').write('?????')"

returns
Traceback (most recent call last):
File "", line 1, in
File "/usr/lib/python2.6/codecs.py", line 686, in write
return self.writer.write(data)
File "/usr/lib/python2.6/codecs.py", line 351, in write
data, consumed = self.encode(object, self.errors)
UnicodeDecodeError: 'ascii' codec can't decode byte 0xd0 in position 0: ordinal not in range(128)

© Stack Overflow or respective owner

Related posts about python

Related posts about unicode