環境
- python2.7
- Apache2.4
問題点
cgitbではHTMLの一行目に<!--: spamが出力されるため、Content-Typeを送信していないとApache側でエラーが発生してしまう。
AH02429: Response header name '<!--' contains invalid characters, aborting request
方法
cgitbのHTML出力前にContent-typeを出力する。
from __future__ import absolute_import, print_function, unicode_literals
import sys
import cgitb
def my_except_hook(exctype, value, traceback):
print('Content-Type: text/html')
print('')
hook = cgitb.Hook()
hook(exctype, value, traceback)
sys.__excepthook__(exctype, value, traceback)
sys.excepthook = my_except_hook