Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 26 additions & 8 deletions tagreader/clients.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
from itertools import groupby
from operator import itemgetter
from typing import Any, Dict, List, Optional, Tuple, Union
from urllib.error import HTTPError

import numpy as np
import pandas as pd
import pytz
import requests

from tagreader.cache import BucketCache, SmartCache
from tagreader.logger import logger
Expand All @@ -21,6 +21,7 @@
PIHandlerWeb,
get_auth_aspen,
get_auth_pi,
get_url_aspen,
list_aspenone_sources,
list_piwebapi_sources,
)
Expand Down Expand Up @@ -121,24 +122,41 @@ def get_handler(
url: Optional[str],
options: Dict[str, Union[int, float, str]],
verify_ssl: Optional[Union[bool, str]],
auth: Optional[Any],
auth: Optional[Any] = None,
cache: Optional[Union[SmartCache, BucketCache]] = None,
):
if imstype is None:
orig_auth = auth
orig_url = url
try:
if datasource in list_aspenone_sources(
aspen_source = list_aspenone_sources(
url=None, auth=None, verify_ssl=verify_ssl
):
imstype = IMSType.ASPENONE
except HTTPError as e:
logger.debug(f"Could not list Aspenone sources: {e}")
)
except requests.exceptions.HTTPError:
# Try again using app registration auth
try:
auth = get_auth_aspen(False)
url = get_url_aspen(False)
aspen_source = list_aspenone_sources(
auth=auth, url=url, verify_ssl=verify_ssl
)
except requests.exceptions.HTTPError as e:
logger.debug(f"Could not list Aspenone sources: {e}")
aspen_source = []

if datasource in aspen_source:
imstype = IMSType.ASPENONE
else:
auth = orig_auth
url = orig_url

if imstype is None:
try:
if datasource in list_piwebapi_sources(
url=None, auth=None, verify_ssl=verify_ssl
):
imstype = IMSType.PIWEBAPI
except HTTPError as e:
except requests.exceptions.HTTPError as e:
logger.debug(f"Could not list PI sources: {e}")

if imstype == IMSType.PIWEBAPI:
Expand Down
Loading