From fa1d52a58a3d1b9ebc5337ac9c19ead986e8b53b Mon Sep 17 00:00:00 2001 From: idealatom Date: Tue, 28 Apr 2020 17:54:02 +0700 Subject: [PATCH] reauthenticate on unexpected 401 errors, fix of marazmiki#10 --- django_selectel_storage/selectel.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/django_selectel_storage/selectel.py b/django_selectel_storage/selectel.py index f1749e0..ddff000 100644 --- a/django_selectel_storage/selectel.py +++ b/django_selectel_storage/selectel.py @@ -76,6 +76,10 @@ def perform_request(self, http_method, key, self.build_url(key), **kwargs ) # type: requests.Response + if resp.status_code == 401: + log.debug('Got an unexpected 401 error, reauthenticate.') + self.authenticate() + return self.perform_request(http_method, key, raise_exception, **kwargs) if raise_exception: resp.raise_for_status() return resp