Skip to content

Instantly share code, notes, and snippets.

@kierdavis
Last active October 28, 2021 16:42
Show Gist options
  • Save kierdavis/87f06292051ebf670acc84cb567b9570 to your computer and use it in GitHub Desktop.
Save kierdavis/87f06292051ebf670acc84cb567b9570 to your computer and use it in GitHub Desktop.
import cgitb
import os
format = os.environ.get("CGITB_FORMAT", "text")
cgitb.enable(format=format, display=0)
raise Exception("oh no")
# [user@host:~]$ python --version
# Python 3.11.0a1
#
# A CGI header block is correctly emitted here (separated from the body by a blank line):
# [user@host:~]$ CGITB_FORMAT=html python repro_cgitb_not_emitting_headers_in_text_mode.py
# <!--: spam
# Content-Type: text/html
#
# <body bgcolor="#f0f0f8"><font color="#f0f0f8" size="-5"> -->
# <body bgcolor="#f0f0f8"><font color="#f0f0f8" size="-5"> --> -->
# </font> </font> </font> </script> </object> </blockquote> </pre>
# </table> </table> </table> </table> </table> </font> </font> </font><p>A problem occurred in a Python script.
#
# No CGI header block is emitted here:
# [user@host:~]$ CGITB_FORMAT=text python repro_cgitb_not_emitting_headers_in_text_mode.py
# <p>A problem occurred in a Python script.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment