From c72e92db185afc874606a8f79cc15b6ed8983bd2 Mon Sep 17 00:00:00 2001 From: Joscha Date: Mon, 6 May 2019 12:04:01 +0000 Subject: [PATCH] Make Ti downloader authentication more robust --- PFERD/ti.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/PFERD/ti.py b/PFERD/ti.py index f01bbd3..3551b8f 100644 --- a/PFERD/ti.py +++ b/PFERD/ti.py @@ -105,6 +105,12 @@ class Ti: self._credentials = None def _download(self, url, to_path): - username, password = self._get_credentials() - with self._session.get(url, stream=True, auth=(username, password)) as r: - stream_to_path(r, to_path) + while True: + username, password = self._get_credentials() + with self._session.get(url, stream=True, auth=(username, password)) as r: + if r.ok: + stream_to_path(r, to_path) + return + else: + print("Incorrect credentials.") + self._reset_credentials()