[ python-Bugs-1059748 ] errors=ignore broken on StreamWriter?

SourceForge.net noreply at sourceforge.net
Wed Nov 3 21:28:46 CET 2004


Bugs item #1059748, was opened at 2004-11-03 21:14
Message generated for change (Comment added) made by lemburg
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1059748&group_id=5470

Category: Unicode
Group: Python 2.3
>Status: Closed
>Resolution: Works For Me
Priority: 5
Submitted By: Wummel (calvin)
Assigned to: M.-A. Lemburg (lemburg)
Summary: errors=ignore broken on StreamWriter?

Initial Comment:
Hi,

when writing wrong-encoded characters to a StreamWriter
I get a UnicodeDecodeError. The question is why
errors="ignore" is not working in this case since there
is an exception raised.

Attached is the script that produced the error.

----------------------------------------------------------------------

>Comment By: M.-A. Lemburg (lemburg)
Date: 2004-11-03 21:28

Message:
Logged In: YES 
user_id=38388

The problem is in your example: 'ä' is an 8-bit string
which is passed to the codec's .encode() method.
Because the Latin-1 codecs expects Unicode as input
to .encode(), Python tries to convert 'ä' to Unicode
assuming it is ASCII - this fails with the exception you
are seeing.

Example:

>>> 'ä'.encode('latin-1')
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe4 in
position 0: ordinal not in range(128)


----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1059748&group_id=5470


More information about the Python-bugs-list mailing list