[Tutor] cgi help

delegbede at dudupay.com delegbede at dudupay.com
Wed Oct 6 13:58:09 CEST 2010

Got it fixed.
Thanks y'all.
------Original Message------
From: Dave Angel
To: Dipo Elegbede
Cc: tutor
Subject: Re: [Tutor] cgi help
Sent: Oct 6, 2010 12:30

On 2:59 PM, Dipo Elegbede wrote:
> here is the code:
> http://pastebin.com/K2Fxq6ac
> kindly help me figure out my mistake.
> It is supposed to return a table of environmental variables but it returns
> only the header and a blank page.
> thanks
Care to define "return" ?

How are you running this code?  How are you trapping and displaying the 
exception it gets when run?  Can you show us the traceback?  Are you 
looking at the output in a web browser?  Which one?  And are you doing a 
view-Source, or whatever your browser offers?

A CGI program is intended to run on a web server, and debugging it can 
be very difficult.  Are you sure you want this as a beginner project?

If so, then I'd start by saying you should run it locally, till you get 
rid of all the errors you'll see that way.

By inspection, I can see that you should get more than the header, you 
should also get the <table> element, then it'll crash on the bogus 
assignment of the uninitialized variable rowNumber.

When I run it locally, I get:

Content-type: text/html

<?xml version = "1.0" encoding = "UTF-8"?>
     "-//W3C//DTD XHTML 1.0 Strict//EN"
<html xmlns = "http://www.w3.org/1999/xhtml">
<head><title>Environmental Variables</title></head>

<table style = "border: 0">
Traceback (most recent call last):
   File "M:\cgitest.py", line 27, in <module>
     rowNumber += 1
NameError: name 'rowNumber' is not defined

You don't initialize the global variable rowNumber to anything, but just 
increment it.

You do initialize a local variable in your function with the same name, 
but nothing is ever done with that, and of course it goes away when the 
function ends.  Same with the backgroundColor local.

To fix this problem you'll need to initialize rowNumber before the for 


Sent from my BlackBerry wireless device from MTN

More information about the Tutor mailing list