cgi problem using FieldStorage().
infotechsys.wayne at verizon.net
infotechsys.wayne at verizon.net
Fri Nov 30 16:18:45 EST 2001
Hi,
I'm learnning cgi and html having a bit of a problem passing values to
my cgi script.
Here is the first script:
========================================
#!/usr/bin/python
theSalesOrder = """Content-type: text/html\n
<html>
<head>The Test</head>
<body>
<form method=get action="/cgi-bin/saleOrderAddProc.py">
<p>Customer PO #:</p>
<input class="customerPONbr" type=text name=customer</input>
<p><input type=submit></p>
</form></body></html>"""
print theSalesOrder
=========================================
Here is the script that is called my the script above:
-------------------------------------------
#!/usr/bin/python
import cgi, sys
sys.stderr = sys.stdin
theSalesOrder = """Content-Type: text/html\n
<html><head><title>
my test
</title></head>
<body><h4>%s</h4>
</body></html>"""
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/saleOrderAddProc.py", line 13, in ?
line1 = form['customer'].value
File "/usr/lib/python1.5/cgi.py", line 907, in __getitem__
raise KeyError, key
KeyError: customer
[Fri Nov 30 15:22:19 2001] [error] [client 127.0.0.1] Premature end of
script headers: /usr/local/Apache/cgi-bin/saleOrderAddProc.py
[Fri Nov 30 15:24:30 2001] [error] [client 127.0.0.1] Premature end of
script headers: /usr/local/Apache/cgi-bin/saleOrderAddProc.py
[Fri Nov 30 15:27:19 2001] [error] [client 127.0.0.1] Premature end of
script headers: /usr/local/Apache/cgi-bin/saleOrderAddProc.py
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.
WHAT AM I DOING WRONG?
Thanks Wayne.
More information about the Python-list
mailing list