tags:

views:

60

answers:

2

I have some python code on both the client and server side. I am getting an IncompleteRead exception thrown for what seems to be no good reason. I can navigate to the URL with Firefox without any error message and also WGET it without any odd results.

The server code is:

import random
import hashlib
print "Content-Type: text/html"     
print                              

m = hashlib.md5()
m.update(str(random.random()))
print m.hexdigest()
print

On the client site, I use a relatively straightforward POST approach:

    data = urllib.urlencode({"username": username,
                     "password" : password})
    #POST in the data.
    req = urllib2.Request(url, data)

    response = urllib2.urlopen(req)
    string =  response.read()

And the response.read() throws the error.

Edit: Further information - Adding explicit CRLF emissions does not alter the change. Checking the error log

[Wed Sep 08 10:36:43 2010] [error] [client 192.168.80.1] (104)Connection reset by peer: ap_content_length_filter: apr_bucket_read() failed

The SSL access log shows(mildly redacted):

192.168.80.1 - - [08/Sep/2010:10:38:02 -0700] "POST /serverfile.py HTTP/1.1" 200 1357 "-" "Python-urllib/2.7"
+1  A: 

Does terminating the lines with \r\n make any difference? Something like this:

import random
import hashlib
import sys

sys.stdout.write("Content-Type: text/html\r\n\r\n")

m = hashlib.md5()
m.update(str(random.random()))
print m.hexdigest()
print
Carlos Valiente
A: 

The problem is a bug in Apache.

Apache throws this particular kind of error when the receiving script does not consume all of the POST request.

Apache developers consider this to be an "As-designed" design.

The fix is to have something like this as soon as possible:

workaround = cgi.FieldStorage()
Paul Nathan