From 9aa52eecb5193e145ec9b396f105b085fb87a456 Mon Sep 17 00:00:00 2001 From: David Shrewsbury Date: Thu, 18 Apr 2013 16:25:14 -0400 Subject: [PATCH] Confirm we have auth creds before clearing preauth If you use the API and supply only preauth values (preauthurl and preauthtoken), and if either of these are incorrect, a non-descriptive AttributeError will be thrown and uncaught: 'NoneType' object has no attribute 'find' The _retry() will fail on the first pass (getting 401), then try to reauthenticate with non-preauth values. If those are not given, particularly the auth url, then the urlparse() call will be supplied None for the url in http_connection() causing the exception above. This change makes sure that we have an auth url, user and key before retrying authentication. Given the situation above, a '401 Unauthorized' ClientException will now be thrown instead of the AttributeError. Change-Id: Ie1b5bde1e8ff321aa18c0f23dbd2960d6e482236 --- swiftclient/client.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/swiftclient/client.py b/swiftclient/client.py index a607898b..bfd794c5 100644 --- a/swiftclient/client.py +++ b/swiftclient/client.py @@ -1035,7 +1035,9 @@ class Connection(object): raise if err.http_status == 401: self.url = self.token = None - if self.attempts > 1: + if self.attempts > 1 or not all((self.authurl, + self.user, + self.key)): raise elif err.http_status == 408: self.http_conn = None