From 7b9f304485b990e0b4e3d4373e28b0ac54ea8a0e Mon Sep 17 00:00:00 2001 From: EdLeafe <ed@leafe.com> Date: Wed, 12 Jun 2013 17:43:01 -0500 Subject: [PATCH] Fixes re-auth flow with expired tokens. The re-authentication of expired tokens assumed that the 401 would always occur on the first HTTP at tempt. This fix changes that so that re-auth is still only attempted once, but no longer has to be on the first attempt. Change-Id: I93a1187da3637287a803a59c146256d4f543c9d5 Fixes: bug #1131142 --- swiftclient/client.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/swiftclient/client.py b/swiftclient/client.py index 04a539c2..3d848cd3 100644 --- a/swiftclient/client.py +++ b/swiftclient/client.py @@ -1034,6 +1034,7 @@ class Connection(object): def _retry(self, reset_func, func, *args, **kwargs): self.attempts = 0 + retried_auth = False backoff = self.starting_backoff while self.attempts <= self.retries: self.attempts += 1 @@ -1055,10 +1056,11 @@ class Connection(object): raise if err.http_status == 401: self.url = self.token = None - if self.attempts > 1 or not all((self.authurl, - self.user, - self.key)): + if retried_auth or not all((self.authurl, + self.user, + self.key)): raise + retried_auth = True elif err.http_status == 408: self.http_conn = None elif 500 <= err.http_status <= 599: