the dummy class definitioncommented out in this final versionwas used to debug the script before it was installed on the net besides not seeing stderr messages by defaultcgi scripts also assume an enclosing context that does not exist if they are tested outside the cgi environment for instanceif run from the system command linethis script has no form input data uncomment this code to test from the system command line the dummy class masquerades as parsed form field objectand form is assigned dictionary containing two form field objects the net effect is that form will be plug-and-play compatible with the result of cgi fieldstorage call as usual in pythonobject interfacesnot datatypesare all we must adhere to here are few general tips for debugging your server-side cgi scriptsrun the script from the command line it probably won' generate html as isbut running it standalone will detect any syntax errors in your code recall that python command line can run source code files regardless of their extensionfor examplepython somescript cgi works fine assign sys stderr to sys stdout as early as possible in your script this will generally make the text of python error messages and stack dumps appear in your client browser when accessing the scriptinstead of the web server' console window or logs short of wading through server logs or manual exception handlingthis may be the only way to see the text of error messages after your script aborts mock up inputs to simulate the enclosing cgi context for instancedefine classes that mimic the cgi inputs interface (as done with the dummy class in this scriptto view the script' output for various test cases by running it from the system command line |setting environment variables to mimic form or url inputs sometimes helpstoo (we'll see how later in this call utilities to display cgi context in the browser the cgi module includes utility functions that send formatted dump of cgi environment variables and input values to the browserto view in reply page for instancecgi print_form(formprints all the input parameters sent from the clientand cgi test(prints environment variablesthe formthe directoryand more sometimes this is enough to resolve connection or input problems we'll use some of these in the webmail case study in the next show exceptions you catchprint tracebacks if you catch an exception that python raisesthe python error message won' be printed to stderr (that is normal behaviorin such casesit' up to your script to |this technique isn' unique to cgi scriptsby the way in we briefly met systems that embed python code inside htmlsuch as python server pages there is no good way to test such code outside the context of the enclosing system without extracting the embedded python code (perhaps by using the html parser html parser that comes with pythoncovered in and running it with passed-in mock-up of the api that it will eventually use server-side scripting