[issue13024] cgitb uses stdout encoding

STINNER Victor report at bugs.python.org
Wed Sep 21 01:02:09 CEST 2011


New submission from STINNER Victor <victor.stinner at haypocalc.com>:

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.

----------
components: Library (Lib)
files: cgitb.patch
keywords: patch
messages: 144356
nosy: haypo
priority: normal
severity: normal
status: open
title: cgitb uses stdout encoding
versions: Python 3.3
Added file: http://bugs.python.org/file23218/cgitb.patch

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue13024>
_______________________________________


More information about the Python-bugs-list mailing list