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: cgitb does not emit CGI headers when format='text'
Type: enhancement Stage: resolved
Components: Library (Lib) Versions: Python 3.11
process
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: Nosy List: eric.smith, kierdavis
Priority: normal Keywords:

Created on 2021-10-28 16:47 by kierdavis, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
repro_cgitb_not_emitting_headers_in_text_mode.py kierdavis, 2021-10-28 16:47 CGI script that demonstrates this behaviour. Usage & output are included in a comment in the script.
Messages (3)
msg405198 - (view) Author: Kier Davis (kierdavis) Date: 2021-10-28 16:47
## 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.
msg406324 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2021-11-14 16:31
I would think the use case for 'text' is to not print the output to a web page, so you wouldn't want the headers. The documentation says that cgitb was generalized to not only produce output for web pages. The 'text' format provides this generalization.

Changing to an enhancement request for 3.11. We can't change the 'text' format because it would break existing code. so this is really an enhancement request for a new format. But I don't see what the use case would be, so I don't think it would be accepted.

What's the case where you need this functionality? How is the 'html' format unacceptable?
msg408339 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2021-12-11 21:18
Having not heard back about a use case for this, I'm going to close it. If you want to move this forward, I suggest proposing it on the python-ideas mailing list.
History
Date User Action Args
2022-04-11 14:59:51adminsetgithub: 89813
2021-12-11 21:18:12eric.smithsetstatus: pending -> closed
resolution: rejected
messages: + msg408339

stage: resolved
2021-11-14 20:14:10eric.smithsetstatus: open -> pending
2021-11-14 16:31:05eric.smithsetversions: - Python 3.6, Python 3.7, Python 3.8, Python 3.9, Python 3.10
nosy: + eric.smith

messages: + msg406324

type: behavior -> enhancement
2021-10-28 16:47:19kierdaviscreate