diff options
Diffstat (limited to 'python2/httplib2/__init__.py')
-rw-r--r-- | python2/httplib2/__init__.py | 35 |
1 files changed, 28 insertions, 7 deletions
diff --git a/python2/httplib2/__init__.py b/python2/httplib2/__init__.py index 58d9ce4..8e9f0fe 100644 --- a/python2/httplib2/__init__.py +++ b/python2/httplib2/__init__.py @@ -22,7 +22,7 @@ __contributors__ = ["Thomas Broyer (t.broyer@ltgt.net)", "Sam Ruby", "Louis Nyffenegger"] __license__ = "MIT" -__version__ = "0.7.7" +__version__ = "0.8" import re import sys @@ -1072,7 +1072,7 @@ try: raise ImportError # Bail out; we're not actually running on App Engine. from google.appengine.api.urlfetch import fetch from google.appengine.api.urlfetch import InvalidURLError - except ImportError: + except (ImportError, AttributeError): from google3.apphosting.api import apiproxy_stub_map if apiproxy_stub_map.apiproxy.GetStub('urlfetch') is None: raise ImportError # Bail out; we're not actually running on App Engine. @@ -1083,7 +1083,7 @@ try: def fixed_fetch(url, payload=None, method="GET", headers={}, allow_truncated=False, follow_redirects=True, deadline=5): - return fetch(url, payload=payload, method=method, headers=header, + return fetch(url, payload=payload, method=method, headers=headers, allow_truncated=allow_truncated, follow_redirects=follow_redirects, deadline=deadline, validate_certificate=validate_certificate) @@ -1118,7 +1118,7 @@ try: 'http': AppEngineHttpConnection, 'https': AppEngineHttpsConnection } -except ImportError: +except (ImportError, AttributeError): pass @@ -1246,7 +1246,10 @@ class Http(object): 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 @@ class Http(object): 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() @@ -1364,7 +1380,10 @@ class Http(object): if response.status in [302, 303]: redirect_method = "GET" body = None - (response, content) = self.request(location, redirect_method, body=body, headers = headers, redirections = redirections - 1) + (response, content) = self.request( + location, method=redirect_method, + body=body, headers=headers, + redirections=redirections - 1) response.previous = old_response else: raise RedirectLimit("Redirected more times than rediection_limit allows.", response, content) @@ -1506,7 +1525,9 @@ class Http(object): # Should cached permanent redirects be counted in our redirection count? For now, yes. if redirections <= 0: raise RedirectLimit("Redirected more times than rediection_limit allows.", {}, "") - (response, new_content) = self.request(info['-x-permanent-redirect-url'], "GET", headers = headers, redirections = redirections - 1) + (response, new_content) = self.request( + info['-x-permanent-redirect-url'], method='GET', + headers=headers, redirections=redirections - 1) response.previous = Response(info) response.previous.fromcache = True else: |