simple http server

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Gelo Ilzi

    simple http server

    I'm trying to implement a very simple http server with cgi functionality.
    The code is simple:

    import CGIHTTPServer, BaseHTTPServer
    httpd = BaseHTTPServer. HTTPServer(('', 8000),
    CGIHTTPServer.C GIHTTPRequestHa ndler)
    httpd.serve_for ever()

    I've created a subdir 'cgi-bin' which contains a python script. Now when I
    enter this directory, i.e., go to the url http://localhost:8000/cgi-bin/ my
    browser shows:

    Error response
    Error code 403.
    Message: CGI script is not a plain file ('/cgi-bin/').
    Error code explanation: 403 = Request forbidden -- authorization will not
    help.

    Plain html pages are ok.

    It seems I misunderstand something very basical. Could somebody help me
    please.

    Thank you in advance.


  • Peter Hansen

    #2
    Re: simple http server

    Gelo Ilzi wrote:
    [color=blue]
    > I've created a subdir 'cgi-bin' which contains a python script. Now when I
    > enter this directory, i.e., go to the url http://localhost:8000/cgi-bin/ my
    > browser shows:
    >
    > Error response
    > Error code 403.
    > Message: CGI script is not a plain file ('/cgi-bin/').
    > Error code explanation: 403 = Request forbidden -- authorization will not
    > help.
    >
    > Plain html pages are ok.
    >
    > It seems I misunderstand something very basical. Could somebody help me
    > please.[/color]

    What did you expect to happen when you went to that URL?

    -Peter

    Comment

    • Kevin Altis

      #3
      Re: simple http server


      "Gelo Ilzi" <geloilzi@hotma il.com> wrote in message
      news:c39rul$dri $1@news2.netvis ion.net.il...[color=blue]
      > I'm trying to implement a very simple http server with cgi functionality.
      > The code is simple:
      >
      > import CGIHTTPServer, BaseHTTPServer
      > httpd = BaseHTTPServer. HTTPServer(('', 8000),
      > CGIHTTPServer.C GIHTTPRequestHa ndler)
      > httpd.serve_for ever()
      >
      > I've created a subdir 'cgi-bin' which contains a python script. Now when I
      > enter this directory, i.e., go to the url http://localhost:8000/cgi-bin/[/color]
      my[color=blue]
      > browser shows:
      >
      > Error response
      > Error code 403.
      > Message: CGI script is not a plain file ('/cgi-bin/').
      > Error code explanation: 403 = Request forbidden -- authorization will[/color]
      not[color=blue]
      > help.
      >
      > Plain html pages are ok.
      >
      > It seems I misunderstand something very basical. Could somebody help me
      > please.
      >
      > Thank you in advance.[/color]

      That is correct behavior, you can't browse the cgi-bin directory. Put a CGI
      script in that directory like the one below to dump the environment
      variables and then go directly to that URL. Depending on your platform and
      location of Python, you might have to change the first line, but this will
      verify your CGIs are working.

      ka
      ---

      #!/usr/local/bin/python
      print "Content-type: text/html\r\n\r\n",
      print '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">'
      print "<html><bod y>"
      print "<pre>"
      import os, sys
      from cgi import escape
      print "<strong>Py thon %s</strong>" % sys.version
      keys = os.environ.keys ()
      keys.sort()
      for k in keys:
      print "%s\t%s" % (escape(k), escape(os.envir on[k]))
      print "</pre>"
      print "</body></html>"


      Comment

      Working...