[New-bugs-announce] [issue45650] cgitb does not emit CGI headers when format='text'
Kier Davis
report at bugs.python.org
Thu Oct 28 12:47:19 EDT 2021
New submission from Kier Davis <me at kierdavis.com>:
## Context ##
* Python is executing a script on behalf of a web server (e.g. Apache httpd) following the CGI protocol.
* cgitb is enabled and configured to use the 'text' format.
* An unhandled exception occurs before any CGI response headers have been emitted.
## Expected behaviour ##
A valid response is returned from the CGI script to the web server and ultimately to the client.
## Observed behaviour ##
The response is rejected by the web server because it does not begin with a valid CGI header block.
[cgi:error] [pid xxxxx] [client xxx.xxx.xxx.xxx:xxxxx] malformed header from script 'web.py': Bad header: <p>A problem occurred in a Pyt
Any traceback info included (if display=1) gets discarded and the web server returns its own Internal Server Error response instead.
## Comments ##
A valid response is observed if format='html'. This bug only concerns format='text'.
The behaviour is the same regardless of whether display=0 or display=1.
I imagine this is because cgitb.reset (which emits the headers) is only called when format='html'.
We could resolve this by always calling cgitb.reset regardless of the format, or by introducing separate text-format and HTML-format versions of cgitb.reset.
I'm happy to prepare a patch if you agree on the approach.
----------
components: Library (Lib)
files: repro_cgitb_not_emitting_headers_in_text_mode.py
messages: 405198
nosy: kierdavis
priority: normal
severity: normal
status: open
title: cgitb does not emit CGI headers when format='text'
type: behavior
versions: Python 3.10, Python 3.11, Python 3.6, Python 3.7, Python 3.8, Python 3.9
Added file: https://bugs.python.org/file50409/repro_cgitb_not_emitting_headers_in_text_mode.py
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue45650>
_______________________________________
More information about the New-bugs-announce
mailing list