-
Notifications
You must be signed in to change notification settings - Fork 136
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
KeyError exception unnecessarily raised #262
Comments
iexfinance/iexfinance/stocks/base.py Lines 92 to 101 in 64ee3af
Something like: 87 def _get_field(self, endpoint, field):
88 try:
89 data = getattr(self, "get_%s" % endpoint)(filter_=field)
90 except AttributeError:
91 raise NotImplementedError("Endpoint %s not implemented." % endpoint)
92 try:
93 if self.output_format == "json":
94 if self.single_symbol:
95 data = data[field]
96 else:
97 data = {symbol: data[symbol][field] for symbol in self.symbols}
98 else:
99 if self.single_symbol:
100 return data[field][0]
101 except KeyError:
102 raise KeyError("Field %s not found in %s." % (field, endpoint))
103 return data |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Format of data that raises the exception:
That is,
data[ticker]['sharesOutstanding']
Traceback:
That's because it's looking for 'sharesOutstanding' directly in the top-level data, which won't have it as it's indexed on ticker for multi-ticker queries.
Might be simpler to, rather than explicitly look for a problem, place this block in a try/except block.
The text was updated successfully, but these errors were encountered: