From 51a8c6ab0dc825230af598b08ddd5b9b28f87d43 Mon Sep 17 00:00:00 2001 From: IP Date: Sat, 2 Nov 2024 07:57:42 -0500 Subject: [PATCH 1/4] styke: added reason to error logging --- custom_components/yahoofinance/coordinator.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/custom_components/yahoofinance/coordinator.py b/custom_components/yahoofinance/coordinator.py index 8612781..c5b8526 100755 --- a/custom_components/yahoofinance/coordinator.py +++ b/custom_components/yahoofinance/coordinator.py @@ -122,7 +122,10 @@ async def initial_navigation(self, url: str) -> ConsentData | None: if response.status != HTTPStatus.OK: _LOGGER.error( - "Failed to navigate to %s, status=%d", url, response.status + "Failed to navigate to %s, status=%d, reason=%s", + url, + response.status, + response.reason, ) return None @@ -170,7 +173,11 @@ async def process_consent(self, consent_data: ConsentData) -> bool: # 200 if response.status != HTTPStatus.OK: - _LOGGER.error("Failed to post consent %d", response.status) + _LOGGER.error( + "Failed to post consent %d, reason=%s", + response.status, + response.reason, + ) return False if response.cookies: @@ -215,7 +222,11 @@ async def try_crumb_page(self) -> str | None: _LOGGER.debug("Crumb page reported %s", self.crumb) return self.crumb - _LOGGER.error("Crumb request responded with status=%d", response.status) + _LOGGER.error( + "Crumb request responded with status=%d, reason=%s", + response.status, + response.reason, + ) if response.status == 429: # Ideally we would want to use the seconds passed back in the header From e42c7f3660dd0b727bb3d7a100b2eaeebd7ceb5a Mon Sep 17 00:00:00 2001 From: IP Date: Sat, 2 Nov 2024 07:58:07 -0500 Subject: [PATCH 2/4] fix: updated header user-agent --- custom_components/yahoofinance/const.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/custom_components/yahoofinance/const.py b/custom_components/yahoofinance/const.py index 21e1a75..f03cd36 100755 --- a/custom_components/yahoofinance/const.py +++ b/custom_components/yahoofinance/const.py @@ -153,7 +153,7 @@ "accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "accept-encoding": "gzip,deflate,br,zstd", "accept-language": "en-US,en;q=0.9", - "user-agent": "Mozilla/5.0 (Linux; Android) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.109 Safari/537.36 CrKey/1.54.248666", + "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36", } """ Headers for all other requests. """ From e7dbe9c50bacb77f9e74102a73963c418d46c9e2 Mon Sep 17 00:00:00 2001 From: IP Date: Sat, 2 Nov 2024 08:03:03 -0500 Subject: [PATCH 3/4] fix: pass current cookies to crumb request --- custom_components/yahoofinance/coordinator.py | 1 + 1 file changed, 1 insertion(+) diff --git a/custom_components/yahoofinance/coordinator.py b/custom_components/yahoofinance/coordinator.py index c5b8526..b15a0b7 100755 --- a/custom_components/yahoofinance/coordinator.py +++ b/custom_components/yahoofinance/coordinator.py @@ -211,6 +211,7 @@ async def try_crumb_page(self) -> str | None: GET_CRUMB_URL, headers=REQUEST_HEADERS, timeout=aiohttp.ClientTimeout(total=REQUEST_TIMEOUT), + cookies=self.cookies, ) as response: _LOGGER.debug("Crumb response status: %d, %s", response.status, response) From 7097960341bc58d8e32b3e0b96efb2c30efad8b1 Mon Sep 17 00:00:00 2001 From: IP Date: Sat, 2 Nov 2024 08:04:43 -0500 Subject: [PATCH 4/4] style: added error log after missing cookies --- custom_components/yahoofinance/coordinator.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/custom_components/yahoofinance/coordinator.py b/custom_components/yahoofinance/coordinator.py index b15a0b7..137cee5 100755 --- a/custom_components/yahoofinance/coordinator.py +++ b/custom_components/yahoofinance/coordinator.py @@ -98,6 +98,9 @@ async def try_get_crumb_cookies(self) -> str | None: ) return None + if self.cookies_missing(): + _LOGGER.error("Attempting to get crumb but have no cookies") + await self.try_crumb_page() return self.crumb