Httplib: Incomplete Read
Solution 1:
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
Solution 2:
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 thisas soon as possible:
workaround = cgi.FieldStorage()
Solution 3:
I got this error when I had failed to completely read the previous response, e.g.:
# This is using an opener from urllib2, but I am guessing similar...
response1 = opener.open(url1)
for line in response1:
m = re.match("href='(.*)'", line):
if m:
url2 = m.group(1) # Grab the URL from line, that's all I want.break# Oops. Apache is mad because I suck.
response2 = opener.open(url2)
for line in response2:
print line
The server gave me "200 OK" on the first request, followed by the data up to the link I was looking for, then waited five minutes on the second open, then gave me "200 OK" on the second request, followed by all the data for the second request, then gave me IncompleteRead on the first request!
I am reading between the lines that the Paul's original script logged into two sites and got the problem on the second site.
I can see how reading two pages in parallel might be a nice feature. So what can I do to gracefully tell the server "No more, thanks?" I solved this by reading through and ignoring the rest of the first request (only 200K in this case).
If I were allowed to comment rather than answer, I'd ask Paul Nathan,
What is
workaround = cgi.FieldStorage()
, what do you mean by as soon as possible, and how does it help here? Have pity on a beginner.
Solution 4:
I'm guessing the original poster was actually running the request twice, succeeding the first time and failing on the second.
I got IncompleteRead (from Apache) when I had failed to completely read the previous response, e.g.:
# This is using an opener from urllib2, but I am guessing similar...
response1 = opener.open(url1)
for line in response1:
m = re.match("href='(.*)'", line):
if m:
url2 = m.group(1) # Grab the URL from line, that's all I want.break# Oops. Apache is mad because I suck.
response2 = opener.open(url2)
for line in response2:
print line
The server gave me "200 OK" on the first request, followed by the data up to the link I was looking for, then waited five minutes on the second open, then gave me "200 OK" on the second request, followed by all the data for the second request, then gave me IncompleteRead ! The error happens (for me) in the second for statement, probably when it hits the end of file there.
I can imagine wanting to have two responses open simultaneously for reading. So the question is, how do I finish with a response? Do I have to read all the data even though I don't need it? No, (urllib.urlopen documentation) the response is like a file, just close it, so for my example,
for line in response1:
m = re.match("href='(.*)'", line):
if m:
url2 = m.group(1) # Grab the URL from line, that's all I want.break
response1.close()
response2 = opener.open(url2)
...
Post a Comment for "Httplib: Incomplete Read"