classification
Title: cgitb uses stdout encoding
Type: Stage:
Components: Library (Lib), Unicode Versions: Python 3.3
process
Status: closed Resolution: out of date
Dependencies: Superseder:
Assigned To: Nosy List: georg.brandl, orsenthil, vstinner
Priority: normal Keywords: patch

Created on 2011-09-20 23:02 by vstinner, last changed 2013-12-17 01:50 by vstinner. This issue is now closed.

Files
File name Uploaded Description Edit
cgitb.patch vstinner, 2011-09-20 23:02 review
Messages (1)
msg144356 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2011-09-20 23:02
cgitb module writes its output to sys.stdout by default and so encode its HTML document into stdout encoding, whereas it doesn't specify the HTML encoding.

Moreover it uses stdout error handler. If the locale encoding is ASCII whereas a filename in the traceback contains a non-ASCII character, it fails to encode the non-ASCII characters. Another error handler should be used, xmlcharrefreplace is a good candidate.

To reproduce this issue, use the following script with ASCII locale encoding and a non-ASCII character in name of the current directory:
---
import cgitb
cgitb.enable()
raise ValueError("Hello World")
---

Attached patch uses a workaround similar to the one used in Log._log() from distutils.logging.
History
Date User Action Args
2013-12-17 01:50:44vstinnersetstatus: open -> closed
resolution: out of date
2011-09-26 13:15:45orsenthilsetnosy: + orsenthil
2011-09-20 23:08:04vstinnersetnosy: + georg.brandl
components: + Unicode
2011-09-20 23:02:08vstinnercreate