HTTP server

Simon Forman rogue_pedro at yahoo.com
Sun Jun 25 18:35:25 CEST 2006


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

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")

What was the error message that accompanied the 403 error?

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

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

Peace,
~Simon




More information about the Python-list mailing list