By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,675 Members | 2,270 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,675 IT Pros & Developers. It's quick & easy.

CGI python use "under a curse"

P: n/a
While waiting for my paid-for web-hosting company to get back to me
about my difficulties running python scripts on their servers...
http://groups.google.com/group/comp....f805bf283acc15
....I went and found a free one as a stopgap. And it worked! I was as
happy as a clam. But then it stopped working. Ah. I stripped the
script down to the same minimalist hello-world effort I used
previously:

#!/usr/local/bin/python
import cgi
print "Content-type: text/html\n"
form = cgi.FieldStorage()
print form["essay"].value

(page here: http://essays.profusehost.net/)

As before, this should print out the contents of a textarea going by
the name of "essay". But it does nothing but throw internal server
errors. 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/sup...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?

TIA for your forbearance etc.

May 7 '07 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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/sup...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.
May 7 '07 #2

P: n/a
On May 7, 2:30 pm, Steven D'Aprano
<ste...@REMOVE.THIS.cybersource.com.auwrote:
On Sun, 06 May 2007 21:30:16 -0700, Adrian Smith wrote:
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.
Well, I thought that, but you know what happens to newbies who come
out with such opinions forcefully. Maybe they have special magic perl
which parses python.
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()
Both give me the same ISE, alas.
Good luck with the "admins" at your hosting company.
Well, it *is* free, and there aren't that many free ones that offer
Python. My paid-for host has sent me a message to say they're
ruminating on my issues, though, so I live in hope.

May 7 '07 #3

P: n/a
Adrian Smith wrote:
On May 7, 2:30 pm, Steven D'Aprano
<ste...@REMOVE.THIS.cybersource.com.auwrote:
>On Sun, 06 May 2007 21:30:16 -0700, Adrian Smith wrote:
>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.

Well, I thought that, but you know what happens to newbies who come
out with such opinions forcefully. Maybe they have special magic perl
which parses python.
>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()

Both give me the same ISE, alas.
>Good luck with the "admins" at your hosting company.

Well, it *is* free, and there aren't that many free ones that offer
Python. My paid-for host has sent me a message to say they're
ruminating on my issues, though, so I live in hope.
I'd go to Cornerhost. You can get a cheap account there and the support
is friendly and knowledgable. 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.

regards
Steve
--
Steve Holden +1 571 484 6266 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://del.icio.us/steve.holden
------------------ Asciimercial ---------------------
Get on the web: Blog, lens and tag your way to fame!!
holdenweb.blogspot.com squidoo.com/pythonology
tagged items: del.icio.us/steve.holden/python
All these services currently offer free registration!
-------------- Thank You for Reading ----------------

May 7 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.