Re: CGI python use "under a curse"



On Sun, 06 May 2007 21:30:16 -0700, Adrian Smith wrote:

The support guy looked at it and gave me this:

Traceback (most recent call last):
File "python1.cgi", line 6, in ?
print form["essay"].value
File "/usr/local/lib/python2.4/cgi.py", line 559, in __getitem__ raise
KeyError, key
KeyError: 'essay'

(http://www.profusehost.net/forum/support/10894-cgi-blink.html)

He says I have a syntax error, though I'm b*ed if I can see where it
could be. Can anyone here suggest anything?


Oh lordy lordy lordy, you've got one fine example of incompetence in
action.

From the support forum:

[quote]
Quote:
perl python1.cgi
\Semicolon seems to be missing at python1.cgi line 3.
syntax error at python1.cgi line 4, near "form "
Execution of python1.cgi aborted due to compilation errors.

Quote:
perl -p python1.cgi
Semicolon seems to be missing at python1.cgi line 3.
syntax error at python1.cgi line 4, near "form "
Execution of python1.cgi aborted due to compilation errors.
[end quote]

The "administrator" John is trying to execute a Python script with Perl.
I notice that you pointed that out to him, and his response was:

[quote]
Sorry for delay. if we try to run this script by python we will get same
error.

python -t python1.cgi
Content-type: text/html

Traceback (most recent call last):
File "python1.cgi", line 6, in ?
print form["essay"].value
File "/usr/local/lib/python2.4/cgi.py", line 559, in __getitem__
raise KeyError, key
KeyError: 'essay'

we can test perl or cgi scripts using perl command.

PLease fix syntax error so it will work fine.
[end quote]

It is NOT the same error. There are NO syntax errors in the script, there
is a runtime error. The so-called administrator is wrong: you can't use
Perl to test just any old CGI scripts. They have to be written in Perl.


I see from the source code on your page that you have a line:

<TEXTAREA NAME="essay" COLS=60 ROWS=20 WRAP=HARD></TEXTAREA>

You have two lines in your cgi script:

form = cgi.FieldStorage()
print form["essay"].value

Having never done cgi programming, I'm not sure what the problem is, but
after reading help(cgi) I'll take a stab in the dark and say try this:

print form.value

It might also help for you to try this:

print form.keys()


Good luck with the "admins" at your hosting company.



--
Steven.
.



Relevant Pages

  • Re: CGI python use "under a curse"
    ... Perl to test just any old CGI scripts. ... which parses python. ... I am no longer a customer and do not stand to gain by this recommendation, but they are a small business that were very helpful to me when I *was* a customer. ...
    (comp.lang.python)
  • Re: Need help with CGI/ DBI error (permissions?)
    ... >> My other Perl CGI scripts that don't use DBI run OK, ... > able to telepathically decipher your web server configuration, ... problems with serving up *Perl* pages. ... you just said that your other CGI scripts run fine. ...
    (comp.lang.perl.misc)
  • Re: cgi invoked .bat script cant access network drives!
    ... [snip stuff about user IDs and permssions wrt CGI scripts run from ... IIS] ... Such questions should not be posted to newsgroups that deal with the ... Perl programming language as they will be unwellcome there. ...
    (comp.lang.perl)
  • RE: Perl Programming within Debian
    ... For command-line scripts, I don't use any extension so that they are ... For CGI scripts, I use .cgi for CGI scripts that run in the traditional ... A standard Debian installation includes the Perl interpreter: ... interpreter, load a Perl interpreter module, or have a Perl ...
    (Debian-User)
  • Re: Perlish dictionary behavior
    ... > type is that if you increment a hash key and the key does not exist, ... > Perl puts a one there. ... > my %thingCounts; ... this would generate a KeyError. ...
    (comp.lang.python)