Discussion:
getting POST vars from BaseHTTPRequestHandler
(too old to reply)
Christopher J. Bottaro
19 years ago
Permalink
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***@doxdesk.com
19 years ago
Permalink
Post by Christopher J. Bottaro
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:***@doxdesk.com
http://www.doxdesk.com/
Loading...