How to use the siphon.http_util.session_manager function in siphon

To help you get started, we’ve selected a few siphon examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Unidata / siphon / examples / Basic_Usage.py View on Github external
"""

# This is currently a placeholder for a better example
from __future__ import print_function

from siphon.catalog import TDSCatalog
from siphon.http_util import session_manager

###########################################
cat = TDSCatalog('http://thredds.ucar.edu/thredds/catalog.xml')
print(list(cat.catalog_refs))

###########################################
# Basic HTTP authentication can also be used by using the HTTP session manager
# and setting some default options for HTTP sessions
session_manager.set_session_options(auth=('username', 'password'))
cat = TDSCatalog('https://rda.ucar.edu/thredds/catalog.xml')
github Unidata / siphon / dev / _downloads / Basic_Usage.py View on Github external
"""

# This is currently a placeholder for a better example
from __future__ import print_function

from siphon.catalog import TDSCatalog
from siphon.http_util import session_manager

###########################################
cat = TDSCatalog('http://thredds.ucar.edu/thredds/catalog.xml')
print(list(cat.catalog_refs))

###########################################
# Basic HTTP authentication can also be used by using the HTTP session manager
# and setting some default options for HTTP sessions
session_manager.set_session_options(auth=('username', 'password'))
cat = TDSCatalog('https://rda.ucar.edu/thredds/catalog.xml')
github Unidata / siphon / siphon / simplewebservice / acis.py View on Github external
-------
    A dictionary of data based on the JSON parameters

    Raises
    ------
    :class: `ACIS_API_Exception`
        When the API is unable to establish a connection or returns
        unparsable data.

    """
    base_url = 'http://data.rcc-acis.org/'  # ACIS Web API URL

    timeout = 300 if method == 'MultiStnData' else 60

    try:
        response = session_manager.create_session().post(base_url + method, json=params,
                                                         timeout=timeout)
        return response.json()
    except requests.exceptions.Timeout:
        raise AcisApiException('Connection Timeout')
    except requests.exceptions.TooManyRedirects:
        raise AcisApiException('Bad URL. Check your ACIS connection method string.')
    except ValueError:
        raise AcisApiException('No data returned! The ACIS parameter dictionary'
                               'may be incorrectly formatted')
github Unidata / siphon / siphon / catalog.py View on Github external
def __init__(self, catalog_url):
        """
        Initialize the TDSCatalog object.

        Parameters
        ----------
        catalog_url : str
            The URL of a THREDDS client catalog

        """
        self.session = session_manager.create_session()

        # get catalog.xml file
        resp = self.session.get(catalog_url)
        resp.raise_for_status()

        # top level server url
        self.catalog_url = resp.url
        self.base_tds_url = _find_base_tds_url(self.catalog_url)

        # If we were given an HTML link, warn about it and try to fix to xml
        if 'html' in resp.headers['content-type']:
            import warnings
            new_url = self.catalog_url.replace('html', 'xml')
            warnings.warn('URL {} returned HTML. Changing to: {}'.format(self.catalog_url,
                                                                         new_url))
            self.catalog_url = new_url