This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: errors=ignore broken on StreamWriter?
Type: Stage:
Components: Unicode Versions: Python 2.3
process
Status: closed Resolution: works for me
Dependencies: Superseder:
Assigned To: lemburg Nosy List: calvin, lemburg
Priority: normal Keywords:

Created on 2004-11-03 20:14 by calvin, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
t.py calvin, 2004-11-03 20:14
Messages (2)
msg22992 - (view) Author: Bastian Kleineidam (calvin) Date: 2004-11-03 20:14
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.
msg22993 - (view) Author: Marc-Andre Lemburg (lemburg) * (Python committer) Date: 2004-11-03 20:28
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)
History
Date User Action Args
2022-04-11 14:56:07adminsetgithub: 41120
2004-11-03 20:14:12calvincreate