From fab96c68e3acfb5403ffe65577563f3cb39e2530 Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Tue, 11 Oct 2011 12:00:38 -0700 Subject: Work around Python 2.7 urllib2 bug If the remote is using authenticated HTTP, but does not have $GIT_URL/clone.bundle files in each repository, an initial sync would fail around 8 projects in due to the library not resetting the number of failures after getting a 404. Work around this by updating the retry counter ourselves. The urllib2 library is also not thread-safe. Make it somewhat safer by wrapping the critical section with a lock. Change-Id: I886e2750ef4793cbe2150c3b5396eb9f10974f7f Signed-off-by: Shawn O. Pearce --- main.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'main.py') diff --git a/main.py b/main.py index 8ffdfcce..22e6fa42 100755 --- a/main.py +++ b/main.py @@ -273,6 +273,15 @@ class _UserAgentHandler(urllib2.BaseHandler): req.add_header('User-Agent', _UserAgent()) return req +class _BasicAuthHandler(urllib2.HTTPBasicAuthHandler): + def http_error_auth_reqed(self, authreq, host, req, headers): + try: + return urllib2.AbstractBasicAuthHandler.http_error_auth_reqed( + self, authreq, host, req, headers) + except: + self.reset_retry_count() + raise + def init_http(): handlers = [_UserAgentHandler()] @@ -287,7 +296,7 @@ def init_http(): pass except IOError: pass - handlers.append(urllib2.HTTPBasicAuthHandler(mgr)) + handlers.append(_BasicAuthHandler(mgr)) if 'http_proxy' in os.environ: url = os.environ['http_proxy'] -- cgit v1.2.3-54-g00ecf