Problems with HTTP Request

Rodolfo S. Carvalho rodolfo.ueg at gmail.com
Fri Jun 22 02:14:39 EDT 2007


Hi folks!

I'm writing my own web server in python, and I'm getting problems to handle
POST requests.
This is a snippet of my code (of an HttpRequest class):

try:
    length = int(self.myRequestHandler.headers.get('content-length', 0))
except ValueError:
    length = 0
pdata = self.myRequestHandler.rfile.read(length)
# extract POST data from pdata

The application is executed normally, the response is sent back to the
client, but something is keeping the connection open. I discovered that the
problem is in the lines above, but no exception is raised. I tested
replacing this line:
pdata = self.myRequestHandler.rfile.read(length)

by this:
pdata = self.myRequestHandler.rfile.read(length-1)

On this way, the web server works fine, and close the connection after
response ends. But my request is uncomplete, because the last char is not
readed.
I don't know what to do anymore. I need help =/

Thanks in advance.

-- 
    Rodolfo Carvalho
     Web Developer
rodolfo.ueg at gmail.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20070622/b92efce1/attachment.html>


More information about the Python-list mailing list