Newbie question about a web server

Frank Millman frank at chagford.com
Mon Aug 20 03:02:47 EDT 2007


Hi all

I have just started to dabble in writing my own web server.

I googled for 'python web server', and this is the first hit -

    http://fragments.turtlemeat.com/pythonwebserver.php

It has the source code for a simple web server, based on HTTPServer
and BaseHTTPRequestHandler.

It demonstrates the concepts of
  - returning a static page
  - constructing and returning a dynamic page
  - sending a form with a POST method, and responding to the result

I typed it in and ran it, and it 'just worked', with one exception.

When responding to the initial request, it sends a 200 response,
followed by a content-type header, followed by an html page. This
works fine.

When responding to the POST data received, it sends a 301 response, no
headers, and then the html page.

This works with a Firefox browser on Linux, but MSW IE6 displays 'the
page cannot be displayed'.

According to the notes, "You don't have to know much about the HTTP
protocol at all. Except some basic that when the client request
something it is a "GET", and when the client sends something it is in
our case a POST. Some basic responce codes like 200 is OK for GET, and
404 is file not found, 301 is OK for a Post."

I googled for 'http response code 301', and found that it is actually
a redirection code. It seems that the notes are misleading.

So I guess my questions are -
  1. what is the correct response for a POST?
     I think the answer is 200.
     However, I assume the author is trying to demonstrate a
particular technique.
     Can anyone explain what that may be.
  2. why does the above work with Firefox?

TIA for any enlightenment.

Frank Millman




More information about the Python-list mailing list