LoginSignup
1
0

More than 3 years have passed since last update.

cgitbのHTML出力前にContent-Typeを送信する

Last updated at Posted at 2020-07-27

環境

  • 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
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0