From 31bc14257838857270f8aec84a479b8c499da13b Mon Sep 17 00:00:00 2001 From: Dawn Smith Date: Thu, 7 Nov 2024 19:17:44 -0500 Subject: [PATCH] [FIX] Ensure immediate exception when login fails --- datman/xnat.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/datman/xnat.py b/datman/xnat.py index 5ae04985..e28dbbef 100644 --- a/datman/xnat.py +++ b/datman/xnat.py @@ -180,8 +180,9 @@ def __init__(self, server, username, password): self.auth = (username, password) try: self.open_session() - except Exception: - raise XnatException(f"Failed to open session with server {server}") + except Exception as e: + raise XnatException( + f"Failed to open session with server {server}. Reason - {e}") def __enter__(self): return self @@ -206,6 +207,15 @@ def open_session(self): logger.debug("Username: {}") response.raise_for_status() + # If password is expired, XNAT returns status 200 and a sea of + # HTML causing later, unexpected, exceptions when using + # the connection. So! Check to see if we got HTML instead of a token. + if '