CGI python use "under a curse"

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Adrian Smith

    #1

    CGI python use "under a curse"

    While waiting for my paid-for web-hosting company to get back to me
    about my difficulties running python scripts on their servers...

    ....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.FieldStorag e()
    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.cg i", 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.

  • Steven D'Aprano

    #2
    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.cg i", 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 "administra tor" 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.cg i", 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.FieldStorag e()
    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.

    Comment

    • Adrian Smith

      #3
      Re: CGI python use &quot;under a curse&quot;

      On May 7, 2:30 pm, Steven D'Aprano
      <ste...@REMOVE. THIS.cybersourc e.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.FieldStorag e()
      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.

      Comment

      • Steve Holden

        #4
        Re: CGI python use &quot;under a curse&quot;

        Adrian Smith wrote:
        On May 7, 2:30 pm, Steven D'Aprano
        <ste...@REMOVE. THIS.cybersourc e.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.FieldStorag e()
        >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.blogs pot.com squidoo.com/pythonology
        tagged items: del.icio.us/steve.holden/python
        All these services currently offer free registration!
        -------------- Thank You for Reading ----------------

        Comment

        Working...