Skip to content

Commit f5df1d5

Browse files
authored
Merge pull request #743 from asafravid/master
self._history() graceful handling in case it fails
2 parents 2d480e0 + a10714d commit f5df1d5

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

yfinance/base.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -522,20 +522,26 @@ def get_cashflow(self, proxy=None, as_dict=False, freq="yearly"):
522522
def get_dividends(self, proxy=None):
523523
if self._history is None:
524524
self.history(period="max", proxy=proxy)
525-
dividends = self._history["Dividends"]
526-
return dividends[dividends != 0]
525+
if self._history is not None and "Dividends" in self._history:
526+
dividends = self._history["Dividends"]
527+
return dividends[dividends != 0]
528+
return []
527529

528530
def get_splits(self, proxy=None):
529531
if self._history is None:
530532
self.history(period="max", proxy=proxy)
531-
splits = self._history["Stock Splits"]
532-
return splits[splits != 0]
533+
if self._history is not None and "Stock Splits" in self._history:
534+
splits = self._history["Stock Splits"]
535+
return splits[splits != 0]
536+
return []
533537

534538
def get_actions(self, proxy=None):
535539
if self._history is None:
536540
self.history(period="max", proxy=proxy)
537-
actions = self._history[["Dividends", "Stock Splits"]]
538-
return actions[actions != 0].dropna(how='all').fillna(0)
541+
if self._history is not None and "Dividends" in self._history and "Stock Splits" in self._history:
542+
actions = self._history[["Dividends", "Stock Splits"]]
543+
return actions[actions != 0].dropna(how='all').fillna(0)
544+
return []
539545

540546
def get_isin(self, proxy=None):
541547
# *** experimental ***

yfinance/utils.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ def empty_df(index=[]):
4545
def get_json(url, proxy=None, session=None):
4646

4747
session = session or _requests
48-
4948
headers = {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36'}
5049
html = session.get(url=url, proxies=proxy, headers=headers).text
5150

0 commit comments

Comments
 (0)