问题
Is there any easy way to debug cgi python programs apart from looking at the log file each time the browser generates an error?
回答1:
You can use the cgitb module. It's as simple as
import cgitb
cgitb.enable()
It doesn't always work (e.g. it won't help you for permission errors, or certain other kinds of errors), but when it does it's quite helpful!
回答2:
You could capture (or form by hand) the data and env variables which the CGI script receives, then plainly run the script under your favorite debugger and feed the data to it.
In order to capture the incoming data you can just dump it from the script in CGI mode to some log file, then re-use under debugger in standalone mode.
来源:https://stackoverflow.com/questions/7956696/debugging-cgi-python