cormorack / yodapy

Your Ocean Data Access in Python
https://cormorack.github.io/yodapy/
MIT License
9 stars 10 forks source link

Bad datasources not caught on set_credentials_file #40

Closed s-kganz closed 6 years ago

s-kganz commented 6 years ago
# set up data access
from yodapy.datasources import OOI
from yodapy.utils import set_credentials_file

set_credentials_file(data_source='foo', username='OOIAPI-CHN725DB03M3AC', token='SAFZTAB3M1')

"foo" credentials are added to .credentials file, and then instantiating OOI() results in:


---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
<ipython-input-3-06d5c975e681> in <module>()
----> 1 ooi = OOI()

c:\users\ganzk\desktop\yodapy\yodapy\yodapy\datasources\ooi\__init__.py in __init__(self)
     37         self._data_streams = pd.read_csv(os.path.join(meta_pth, 'data_streams.csv')).fillna('')  # noqa
     38 
---> 39         self._client = M2MClient()
     40         self._session = requests.session()
     41         self.username = self._client.api_username

c:\users\ganzk\desktop\yodapy\yodapy\yodapy\datasources\ooi\m2m_client.py in __init__(self, timeout, api_username, api_token)
     86         self._logger.info(
     87             'Creating M2mClient instance ({:s})'.format(self._base_url))
---> 88         self.base_url = self._base_url
     89 
     90     @property

c:\users\ganzk\desktop\yodapy\yodapy\yodapy\datasources\ooi\m2m_client.py in base_url(self, url)
    103     def base_url(self, url):
    104         self._logger.debug('Setting UFrame credentials.')
--> 105         self._use_existing_credentials()
    106 
    107         self._logger.debug('Setting UFrame base url: {:s}'.format(url))

c:\users\ganzk\desktop\yodapy\yodapy\yodapy\datasources\ooi\m2m_client.py in _use_existing_credentials(self)
    428             import json
    429             with open(CREDENTIALS_FILE) as f:
--> 430                 creds = json.load(f)['ooi']
    431                 self._api_username = creds['username']
    432                 self._api_token = creds['api_key']

KeyError: 'ooi'