Index: python2/httplib2/__init__.py |
=================================================================== |
--- a/python2/httplib2/__init__.py |
+++ b/python2/httplib2/__init__.py |
@@ -1246,7 +1246,10 @@ |
self.authorizations = [] |
def _conn_request(self, conn, request_uri, method, body, headers): |
- for i in range(RETRIES): |
+ i = 0 |
+ seen_bad_status_line = False |
+ while i < RETRIES: |
+ i += 1 |
try: |
if hasattr(conn, 'sock') and conn.sock is None: |
conn.connect() |
@@ -1284,6 +1287,19 @@ |
continue |
try: |
response = conn.getresponse() |
+ except httplib.BadStatusLine: |
+ # If we get a BadStatusLine on the first try then that means |
+ # the connection just went stale, so retry regardless of the |
+ # number of RETRIES set. |
+ if not seen_bad_status_line and i == 1: |
+ i = 0 |
+ seen_bad_status_line = True |
+ conn.close() |
+ conn.connect() |
+ continue |
+ else: |
+ conn.close() |
+ raise |
except (socket.error, httplib.HTTPException): |
if i < RETRIES-1: |
conn.close() |