Skip to content

Commit 93af35a

Browse files
author
Shlomi Kushchi
authored
Merge pull request #284 from alpacahq/fix_empty_response_aggs
Fix TypeError: 'NoneType' object is not iterable when getting empty response from polygon Aggs api
2 parents 55dfe43 + d9c6b0d commit 93af35a

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

alpaca_trade_api/polygon/entity.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,14 @@ def __init__(self, raw):
9393
])
9494

9595
def _raw_results(self):
96-
return self._raw.get('results', [])
96+
results = self._raw.get('results')
97+
if not results:
98+
# this is not very pythonic but it's written like this because
99+
# the raw response for empty aggs was None, and this:
100+
# self._raw.get('results', []) returns None, not [] which breaks
101+
# when we try to iterate it.
102+
return []
103+
return results
97104

98105
def rename_keys(self):
99106
colmap = {

0 commit comments

Comments
 (0)