diff --git a/bin/dm_link.py b/bin/dm_link.py index 8de9f768..756a1201 100755 --- a/bin/dm_link.py +++ b/bin/dm_link.py @@ -205,7 +205,8 @@ def link_archive(archive_path, dicom_path, scanid_field, config): scanid = get_scanid_from_header(archive_path, scanid_field) if not scanid: - logger.error("Scanid not found for archive: {}".format(archive_path)) + logger.error("Scanid not found for archive, please add intended ID " + f"to 'scans.csv': {archive_path}") return try: diff --git a/bin/dm_link_shared_ids.py b/bin/dm_link_shared_ids.py index 1773f248..14318faa 100755 --- a/bin/dm_link_shared_ids.py +++ b/bin/dm_link_shared_ids.py @@ -186,7 +186,7 @@ def share_session(record, xnat_connection=None): target_cfg = datman.config.config(study=str(target)) try: - target_tags = list(target_cfg.get_tags(site=source.site)) + target_tags = list(target_cfg.get_tags(site=target.site)) except Exception: target_tags = [] diff --git a/bin/dm_redcap_scan_completed.py b/bin/dm_redcap_scan_completed.py index e60c9fb8..d2e302e8 100755 --- a/bin/dm_redcap_scan_completed.py +++ b/bin/dm_redcap_scan_completed.py @@ -89,12 +89,14 @@ def add_session_redcap(record, record_key): try: datman.scanid.is_scanid(subject_id) except datman.scanid.ParseException: - logger.error('Invalid session: {}, skipping'.format(subject_id)) + logger.error(f'Invalid session {subject_id} in record {record_id}, ' + 'skipping. Please fix ID on REDCap.') return try: ident = parse_id(subject_id) except datman.scanid.ParseException: - logger.error('Invalid session: {}, skipping'.format(subject_id)) + logger.error(f'Invalid session {subject_id} in record {record_id}, ' + 'skipping. Please fix ID on REDCap.') return session_date = record[get_setting('RedcapDate', default='date')] diff --git a/bin/dm_xnat_extract.py b/bin/dm_xnat_extract.py index 1c1bb885..021e6b6e 100755 --- a/bin/dm_xnat_extract.py +++ b/bin/dm_xnat_extract.py @@ -380,8 +380,8 @@ def get_experiment_identifier(config, project, experiment_id): try: ident = validate_subject_id(experiment_id, config) except datman.scanid.ParseException: - logger.error(f"Invalid experiment ID {experiment_id} in project " - f"{project}.") + logger.error(f"Invalid XNAT experiment ID {experiment_id} in project " + f"{project}. Please update XNAT with correct ID.") return if ident.session is None and not datman.scanid.is_phantom(ident): 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 '