Help with POST request.

Gustavo Cordova gcordova at hebmex.com
Fri Mar 29 17:09:00 EST 2002


Hello all.

I'm having some trouble using the BaseHTTPServer.BaseHTTPRequestHandler
class.

It says in it's internal documentation, that to process
a GET or a POST request (or HEAD, or whatever), just define
a do_<COMMAND> method in a derived class, and let'r rip.

Well, I'm having some trouble accepting POST requests.
GET requests work like a charm, really nice and quick,
but POST requests stay hung and I have to kill them
from the browser.

I'm surely doing something wrong, but I really don't know
how. Here's the script I'm playing with:

===========================================================
import BaseHTTPServer

SIMPLE_WEB_FORM = """ ... a little web page in HTML ..."""

class TestHTTPRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
    def test_response(self):
        # Always so positive.
        self.send_response(200)
        self.send_header("Content-type", "text/html")
        self.end_headers()

    def do_GET(self):
        self.test_response()
        self.wfile.write(SIMPLE_WEB_FORM)

    def do_POST(self):
        self.test_response()
        print "-" * 60
        print self.rfile.read()
        print "-" * 60
        self.wfile.write(SIMPLE_WEB_FORM)

BaseHTTPServer.test(TestHTTPRequestHandler, BaseHTTPServer.HTTPServer)

===========================================================

OK, the problem is I can't ever see what's being sent via POST,
it hangs when reading from the rfile object.

I'd appreciate any and all comments.
-- 
Gustavo Córdova Avila
> gcordova at sismex.com
Å 8351-3861 | 8351-3862




More information about the Python-list mailing list