we need to retry when we get BadStatusLine

this is caused by the http keep alive being closed by the server
This commit is contained in:
Damien Elmes 2013-11-26 02:43:59 +09:00
parent d506515564
commit 6ed971cb6b

View File

@ -448,7 +448,9 @@ httplib.HTTPConnection.send = _incrementalSend
# this is an augmented version of httplib's request routine that: # this is an augmented version of httplib's request routine that:
# - doesn't assume requests will be tried more than once # - doesn't assume requests will be tried more than once
# - calls a hook for each chunk of data so we can update the gui # - calls a hook for each chunk of data so we can update the gui
# - retries only when keep-alive connection is closed
def _conn_request(self, conn, request_uri, method, body, headers): def _conn_request(self, conn, request_uri, method, body, headers):
for i in range(2):
try: try:
if conn.sock is None: if conn.sock is None:
conn.connect() conn.connect()
@ -470,6 +472,11 @@ def _conn_request(self, conn, request_uri, method, body, headers):
raise raise
try: try:
response = conn.getresponse() response = conn.getresponse()
except httplib.BadStatusLine:
print "retry bad line"
conn.close()
conn.connect()
continue
except (socket.error, httplib.HTTPException): except (socket.error, httplib.HTTPException):
raise raise
else: else: