cgi problem using FieldStorage().

infotechsys.wayne at infotechsys.wayne at
Fri Nov 30 22:18:45 CET 2001

I'm learnning cgi and html  having a bit of a problem passing values to 
my cgi script.
Here is the first script:

theSalesOrder = """Content-type: text/html\n
<head>The Test</head>
<form method=get action="/cgi-bin/">
<p>Customer PO #:</p>
<input class="customerPONbr" type=text name=customer</input>
<p><input type=submit></p>

print theSalesOrder

Here is the script that is called my the script above:
import cgi, sys
sys.stderr = sys.stdin

theSalesOrder = """Content-Type: text/html\n
my test

form = cgi.FieldStorage()
line1 = form['customer'].value

print theSalesOrder % (line1)


I'm running Redhat 7.1 with the lastest release of mozilla, althought I get
my error if I use Netscape 4.X, and I'm using Apache 1.3.20.
Here the error from apache's error-log:

[wayne at localhost online-ledger]$  tail  /usr/local/Apache/logs/error_log
Traceback (innermost last):
  File "/usr/local/Apache/cgi-bin/", line 13, in ?
    line1 = form['customer'].value
  File "/usr/lib/python1.5/", line 907, in __getitem__
    raise KeyError, key
KeyError: customer
[Fri Nov 30 15:22:19 2001] [error] [client] Premature end of 
script headers: /usr/local/Apache/cgi-bin/
[Fri Nov 30 15:24:30 2001] [error] [client] Premature end of 
script headers: /usr/local/Apache/cgi-bin/
[Fri Nov 30 15:27:19 2001] [error] [client] Premature end of 
script headers: /usr/local/Apache/cgi-bin/

When I enter data in the first script  and submit it, I set the 
following URL address in my browser;
http://localhost/cgi-bin/salesOrderAddProc?customer%3C%2Finput=data entered
If I remove the %3C%2Finput and run that it works.

Thanks Wayne.

More information about the Python-list mailing list