Skip to content
This repository has been archived by the owner on Nov 16, 2023. It is now read-only.

APAPIKeyException: AP API key is not set. #318

Open
actongorton opened this issue May 24, 2018 · 2 comments
Open

APAPIKeyException: AP API key is not set. #318

actongorton opened this issue May 24, 2018 · 2 comments

Comments

@actongorton
Copy link

API Key is being set but not passed.

Example:

e = api.Election(
    electiondate='2016-11-08', 
    datafile=None, 
    testresults=False, 
    liveresults=True, 
    is_test=False,
    api_key={api_key_as_string}
)
raw_races = e.get_raw_races()
race_objs = e.get_race_objects(raw_races)

Other classes work:

ballot_measures = e.ballot_measures
candidate_reporting_units = e.candidate_reporting_units
candidates = e.candidates
races = e.races
reporting_units = e.reporting_units
results = e.results

Stack Trace:

---------------------------------------------------------------------------
APAPIKeyException                         Traceback (most recent call last)
<ipython-input-17-4946a8f26018> in <module>()
----> 1 raw_races = e.get_raw_races()
      2 race_objs = e.get_race_objects(raw_races)

~/venv-science/lib/python3.6/site-packages/elex/api/models.py in get_raw_races(self, **params)
    963                 return payload
    964         else:
--> 965             payload = self.get(self.electiondate, **params)
    966             return payload
    967 

~/venv-science/lib/python3.6/site-packages/elex/api/models.py in get(self, path, **params)
    904             A dict of optional parameters to be included in API request.
    905         """
--> 906         self._response = utils.api_request('/elections/{0}'.format(path), **params)
    907         return self._response.json()
    908 

~/venv-science/lib/python3.6/site-packages/elex/api/utils.py in api_request(path, **params)
     92 
     93     if not params['apiKey']:
---> 94         raise APAPIKeyException()
     95 
     96     params['format'] = 'json'

APAPIKeyException: AP API key is not set.

@mileswwatkins
Copy link
Contributor

It looks like the races method is a convenience property on top of get_raw_races. The rest of the methods you mentioned are also convenience properties. get_raw_races isn't aware of the API key unless it's passed in via one of those convenience properties.

eg, https://github.com/newsdev/elex/blob/master/elex/api/models.py#L1052

@palewire
Copy link
Contributor

Does e.races not get you what you want here?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants