HTTP server

placid Bulkan at gmail.com
Sun Jun 25 20:34:46 EDT 2006


Simon Forman wrote:
> placid wrote:
> > Simon Forman wrote:
> > >
> ...
> > > For what you're asking about you'd probably want to use the
> > > CGIHTTPRequestHandler from the CGIHTTPServer module instead.  Check out
> > > http://docs.python.org/lib/module-CGIHTTPServer.html
> >
> > This is what i was after, thanks for the tip.
> >
>
> You're welcome, my pleasure.  : )
>
> ...
> >
> > Im having trouble running the following cgi script on windows
> >
> > <code>
> >
> > #!c:/Python/python.exe -u
> >
> > text = """Content-type: text/html
> >
> > <TITLE> CGI 101 </TITLE>
> > <H1>A Second CGI script</H1>
> > <HR>
> > <P>Hello, CGI World!</P>
> > """
> > print text
> >
> > </code>
> >
> >
> > using this http server from
> > http://effbot.org/librarybook/cgihttpserver.htm
> >
> > <code>
> >
> > import CGIHTTPServer
> > import BaseHTTPServer
> >
> > class Handler(CGIHTTPServer.CGIHTTPRequestHandler):
> >     cgi_directories = ["/cgi"]
> >
> > PORT = 8000
> >
> > httpd = BaseHTTPServer.HTTPServer(("", PORT), Handler)
> > print "serving at port", PORT
> > httpd.serve_forever()
> >
> > </code>
> >
> > i get the error number 403, when i try to access the cgi script which
> > is located in a subdirectory called cgi where this file is (http
> > server). I have a feeling that i need to change the Handler class or
> > something, implement , but i couldnt find any examples other then this
> > from eff-bot.
> >
> > It could also be this line of code, that a google search turned up, its
> > the way of running cgi scripts on windows
> >
> > #!c:/Python/python.exe -u
> >
> >
> > Cheers
>
>
> Your cgi and server scripts look fine to me.
>
> Some diagnostic questions:
>
> What is the filename of your cgi script?
> (It must end in ".py" or ".pyw" for CGIHTTPRequestHandler to recognize
> it as a python script.  See the is_python() method in the handler
> class.  Also, in this case the "#!c:/Python/python.exe -u" line isn't
> needed, but it doesn't hurt.  CGIHTTPRequestHandler should find the
> python interpreter for you without it.)

The file was named test.cgi. I changed it too test.py and it worked

>
> What was the exact URL that you're using to try to reach your script?
> (It should look something like:
> "http://localhost:8000/cgi/myscript.py")

i was trying to access it at http://localhost:8000/test.cgi
which i now know is wrong.

>
> What was the error message that accompanied the 403 error?


>
> Did you start the server script from the directory it's in?

i started the server one directory above the cgi directory

> What was the log output from your server script when you tried to
> access the cgi script?

The error message outputted by the server was
localhost - - [26/Jun/2006 09:56:53] code 403, message CGI script is
not a plain file ('/cgi/')


Thanks for the help. I got it to work now.

Cheers




More information about the Python-list mailing list