CGI python use "under a curse"

A

Adrian Smith

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...&q=adrian+smith&rnum=1&hl=en#4ff805bf283acc15
....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/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?

TIA for your forbearance etc.
 
S

Steven D'Aprano

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:
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:

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.
 
A

Adrian Smith

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.
 
S

Steve Holden

Adrian said:
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 ----------------
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,968
Messages
2,570,150
Members
46,697
Latest member
AugustNabo

Latest Threads

Top