diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 676b50b16..8459a6062 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,6 +1,12 @@ Change Log =========== +0.2.33 +------ +Cookie fixes: +- fix backup strategy #1759 +- fix Ticker(ISIN) #1760 + 0.2.32 ------ Add cookie & crumb to requests #1657 diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md new file mode 100644 index 000000000..048fca3f3 --- /dev/null +++ b/CODE_OF_CONDUCT.md @@ -0,0 +1,15 @@ +# Code of Conduct + +## Submitting a new issue + +* Search through existing Issues and Discussions, in case your issue already exists and a solution is being developed. +* Ensure you read & follow the template form. +* Consider you may be the best person to investigate and fix. + +## Contributing to an existing Issue + +* Read the entire thread. +* Ensure your comment is contributing something new/useful. Remember you can simply react to other comments. +* Be concise: + - use the formatting options + - if replying to a big comment, instead of quoting it, link to it diff --git a/meta.yaml b/meta.yaml index 786ffd590..240142573 100644 --- a/meta.yaml +++ b/meta.yaml @@ -1,5 +1,5 @@ {% set name = "yfinance" %} -{% set version = "0.2.32" %} +{% set version = "0.2.33" %} package: name: "{{ name|lower }}" diff --git a/yfinance/base.py b/yfinance/base.py index 568f5684a..2d1b7b398 100644 --- a/yfinance/base.py +++ b/yfinance/base.py @@ -71,10 +71,10 @@ def __init__(self, ticker, session=None, proxy=None): self._data: YfData = YfData(session=session) - self._analysis = Analysis(self._data, ticker) - self._holders = Holders(self._data, ticker) - self._quote = Quote(self._data, ticker) - self._fundamentals = Fundamentals(self._data, ticker) + self._analysis = Analysis(self._data, self.ticker) + self._holders = Holders(self._data, self.ticker) + self._quote = Quote(self._data, self.ticker) + self._fundamentals = Fundamentals(self._data, self.ticker) self._fast_info = None @@ -1741,6 +1741,12 @@ def get_mutualfund_holders(self, proxy=None, as_dict=False): def get_info(self, proxy=None) -> dict: self._quote.proxy = proxy or self.proxy data = self._quote.info + try: + holders = self.get_institutional_holders() + expenseRatio = holders[holders[0] == 'Expense Ratio (net)'][1].values[0] + data['annualNetExpenseRatio'] = expenseRatio + except Exception: + pass return data def get_fast_info(self, proxy=None): diff --git a/yfinance/data.py b/yfinance/data.py index b3791154b..4906e6f4d 100644 --- a/yfinance/data.py +++ b/yfinance/data.py @@ -99,7 +99,6 @@ def _set_cookie_strategy(self, strategy, have_lock=False): self._cookie_lock.acquire() try: - self._cookie_strategy = strategy if self._cookie_strategy == 'csrf': utils.get_yf_logger().debug(f'toggling cookie strategy {self._cookie_strategy} -> basic') self._session.cookies.clear() @@ -203,6 +202,7 @@ def _get_crumb_basic(self, proxy=None, timeout=30): crumb_response = self._session.get(**get_args) self._crumb = crumb_response.text if self._crumb is None or '' in self._crumb: + utils.get_yf_logger().debug("Didn't receive crumb") return None utils.get_yf_logger().debug(f"crumb = '{self._crumb}'") @@ -215,7 +215,7 @@ def _get_cookie_and_crumb_basic(self, proxy, timeout): return cookie, crumb def _get_cookie_csrf(self, proxy, timeout): - if utils.reuse_cookie and self._cookie is not None: + if self._cookie is not None: utils.get_yf_logger().debug('reusing cookie') return True @@ -239,6 +239,7 @@ def _get_cookie_csrf(self, proxy, timeout): soup = BeautifulSoup(response.content, 'html.parser') csrfTokenInput = soup.find('input', attrs={'name': 'csrfToken'}) if csrfTokenInput is None: + utils.get_yf_logger().debug('Failed to find "csrfToken" in response') return False csrfToken = csrfTokenInput['value'] utils.get_yf_logger().debug(f'csrfToken = {csrfToken}') @@ -299,6 +300,7 @@ def _get_crumb_csrf(self, proxy=None, timeout=30): self._crumb = r.text if self._crumb is None or '' in self._crumb or self._crumb == '': + utils.get_yf_logger().debug("Didn't receive crumb") return None utils.get_yf_logger().debug(f"crumb = '{self._crumb}'") @@ -363,6 +365,7 @@ def get(self, url, user_agent_headers=None, params=None, proxy=None, timeout=30) 'headers': user_agent_headers or self.user_agent_headers } response = self._session.get(**request_args) + utils.get_yf_logger().debug(f'response code={response.status_code}') if response.status_code >= 400: # Retry with other cookie strategy if strategy == 'basic': @@ -374,6 +377,7 @@ def get(self, url, user_agent_headers=None, params=None, proxy=None, timeout=30) if strategy == 'basic': request_args['cookies'] = {cookie.name: cookie.value} response = self._session.get(**request_args) + utils.get_yf_logger().debug(f'response code={response.status_code}') return response diff --git a/yfinance/version.py b/yfinance/version.py index d90cee3fb..41c258c8a 100644 --- a/yfinance/version.py +++ b/yfinance/version.py @@ -1 +1 @@ -version = "0.2.32" +version = "0.2.33"