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.

Author kierdavis
Recipients kierdavis
Date 2021-10-28.16:47:19
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1635439639.23.0.69927337911.issue45650@roundup.psfhosted.org>
In-reply-to
Content
## 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.
History
Date User Action Args
2021-10-28 16:47:19kierdavissetrecipients: + kierdavis
2021-10-28 16:47:19kierdavissetmessageid: <1635439639.23.0.69927337911.issue45650@roundup.psfhosted.org>
2021-10-28 16:47:19kierdavislinkissue45650 messages
2021-10-28 16:47:19kierdaviscreate