getting POST vars from BaseHTTPRequestHandler

  • Thread starter Christopher J. Bottaro
  • Start date
C

Christopher J. Bottaro

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

and-google

Christopher said:
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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,527
Members
45,000
Latest member
MurrayKeync

Latest Threads

Top