Can't get a simple CGI script to print HTML - what am I doing wrong??

Steve Holden sholden at holdenweb.com
Tue Dec 17 23:46:32 EST 2002


"Randy Burgess" <rburgess1 at hvc.rr.com> wrote ...
> Hi all,
>
> I'm trying to develop some simple Python scripts to run on my web site at
> http://usable-thought.com. However my testing is running into major
> problems!
>
> My hosting service, hostway.com, runs Python 1.5.1 on the server, which is
> Unix-based and I'm assuming is probably Apache. I can get some crude test
> scripts to work - for example, I can import cgi and run cgi.test() - but I
> can't get some other, equally crude scripts to print basic HTML. They run
> fine off the command line when I'm in a SSH session, but when I try to
> access them via browser, I get an "internal server error." I have made
sure
> file permissions are OK, but this doesn't help. I'm pretty sure the path
> name to Python is correct, since it works for the cgi import.
>
Hmmm, I thought Hostway would be more up to date than 1.5.1. They are
supposed to be pretty Python-savvy. Have you asked their support staff for
help, or looked in their FAQ? Doesn't seem terribly comprehensive, but there
is *some* information there.

If you *do* talk to the support staff, be sure to ask them whetehr they also
have Python 2.x available. I'd be surprised if they don't.

> Here's an example of a script that utterly refuses to work:
>
> #!/usr/bin/env python
> print "Content-type: text/html"
> print
> print "<H3>What follows is a test.</H3>"
>
> What could be simpler? Yet I can't get it to print html in the browser -
> just that frustrating "internal server error." I have gone through the
> documentation for Python 1.5.1, including the page on debugging CGI
> scripts - http://www.python.org/doc/1.5.1p1/lib/node168.html - but am
making
> no headway.
>
> Is there something simple I am overlooking?!?
>
> thanks for any help,

There are many possible causes. The most likely are one or more of:

    You didn't use the right extension of the file (it might need
    to be called *.cgi rather than *.py to be recognised as executable)

    You didn't make the PythonCGI script file executable with a
    chmod +x filename.cgi command

    Your server doesn't recognise the file as a CGI script because
     it's in the wrong directory

However you seem to have covered most of the above in your post. When you
say the cgi test script *works*, do you mean you got it to run as a CGI?

If so, test to see you haven't got any extraneous carriage returns in your
file left over from a previous incernation as a DOS or Windows file.

If none of this helps, take the advice of the first responder and see if you
can't find out from the server error logs what the problem might be. I knwo
these things are frustrating -- I remember almost tearing my hair out when I
first started trying to get http://pydish.holdenweb.com going, but once you
get there you never seem to repeat your original mistakes again :-).

regards
-----------------------------------------------------------------------
Steve Holden                                  http://www.holdenweb.com/
Python Web Programming                 http://pydish.holdenweb.com/pwp/
Bring your musical instrument to PyCon!    http://www.python.org/pycon/
-----------------------------------------------------------------------






More information about the Python-list mailing list