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:
parent
d506515564
commit
6ed971cb6b
85
aqt/sync.py
85
aqt/sync.py
@ -448,46 +448,53 @@ 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):
|
||||||
try:
|
for i in range(2):
|
||||||
if conn.sock is None:
|
try:
|
||||||
conn.connect()
|
if conn.sock is None:
|
||||||
conn.request(method, request_uri, body, headers)
|
conn.connect()
|
||||||
except socket.timeout:
|
conn.request(method, request_uri, body, headers)
|
||||||
raise
|
except socket.timeout:
|
||||||
except socket.gaierror:
|
raise
|
||||||
conn.close()
|
except socket.gaierror:
|
||||||
raise httplib2.ServerNotFoundError(
|
conn.close()
|
||||||
"Unable to find the server at %s" % conn.host)
|
raise httplib2.ServerNotFoundError(
|
||||||
except httplib2.ssl_SSLError:
|
"Unable to find the server at %s" % conn.host)
|
||||||
conn.close()
|
except httplib2.ssl_SSLError:
|
||||||
raise
|
conn.close()
|
||||||
except socket.error, e:
|
raise
|
||||||
conn.close()
|
except socket.error, e:
|
||||||
raise
|
conn.close()
|
||||||
except httplib.HTTPException:
|
raise
|
||||||
conn.close()
|
except httplib.HTTPException:
|
||||||
raise
|
conn.close()
|
||||||
try:
|
raise
|
||||||
response = conn.getresponse()
|
try:
|
||||||
except (socket.error, httplib.HTTPException):
|
response = conn.getresponse()
|
||||||
raise
|
except httplib.BadStatusLine:
|
||||||
else:
|
print "retry bad line"
|
||||||
content = ""
|
conn.close()
|
||||||
if method == "HEAD":
|
conn.connect()
|
||||||
response.close()
|
continue
|
||||||
|
except (socket.error, httplib.HTTPException):
|
||||||
|
raise
|
||||||
else:
|
else:
|
||||||
buf = StringIO()
|
content = ""
|
||||||
while 1:
|
if method == "HEAD":
|
||||||
data = response.read(CHUNK_SIZE)
|
response.close()
|
||||||
if not data:
|
else:
|
||||||
break
|
buf = StringIO()
|
||||||
buf.write(data)
|
while 1:
|
||||||
runHook("httpRecv", len(data))
|
data = response.read(CHUNK_SIZE)
|
||||||
content = buf.getvalue()
|
if not data:
|
||||||
response = httplib2.Response(response)
|
break
|
||||||
if method != "HEAD":
|
buf.write(data)
|
||||||
content = httplib2._decompressContent(response, content)
|
runHook("httpRecv", len(data))
|
||||||
return (response, content)
|
content = buf.getvalue()
|
||||||
|
response = httplib2.Response(response)
|
||||||
|
if method != "HEAD":
|
||||||
|
content = httplib2._decompressContent(response, content)
|
||||||
|
return (response, content)
|
||||||
|
|
||||||
httplib2.Http._conn_request = _conn_request
|
httplib2.Http._conn_request = _conn_request
|
||||||
|
Loading…
Reference in New Issue
Block a user