getting POST vars from BaseHTTPRequestHandler

Discussion in 'Python' started by Christopher J. Bottaro, Jun 26, 2006.

  1. Hi,

    I can't for the life of me figure out how to get the post vars when using
    basehttpserver. Here's my code:

    <code>

    class MyHandler(BaseHTTPRequestHandler):

    def do_POST(self):
    print self.path, self.command
    if self.rfile:
    print self.rfile.read()
    else:
    print 'no data'

    server = HTTPServer(('', 80), MyHandler)
    server.serve_forever()

    </code>

    When I make a post, it just hangs (in self.rfile.read()).

    Thanks for the help.
     
    Christopher J. Bottaro, Jun 26, 2006
    #1
    1. Advertising

  2. Christopher J. Bottaro

    Guest

    Christopher J. Bottaro wrote:

    > When I make a post, it just hangs (in self.rfile.read()).


    I don't know about BaseHTTPRequestHandler in particular, but in general
    you don't want to call an unlimited read() on an HTTP request - it will
    try to read the entire incoming stream, up until the stream is ended by
    the client dropping the connection (by which point it's too late to
    send a response).

    Instead you'll normally want to read the request's Content-Length
    header (int(os.environ['CONTENT_LENGTH']) under CGI) and read(that
    many) bytes.

    --
    And Clover
    mailto:
    http://www.doxdesk.com/
     
    , Jun 28, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jon

    app vars and cache vars

    Jon, Dec 14, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    404
  2. Ben
    Replies:
    2
    Views:
    422
    bromden
    Oct 19, 2003
  3. Maksim Kasimov
    Replies:
    1
    Views:
    807
    notanotheridiot
    Jul 13, 2006
  4. Linuxguy123
    Replies:
    7
    Views:
    705
    Paddy O'Loughlin
    Feb 20, 2009
  5. caccolangrifata
    Replies:
    18
    Views:
    404
    Chris Torek
    Jul 22, 2011
Loading...

Share This Page