Skip to content
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

Pass cookies to getcrumb #143

Merged
merged 4 commits into from
Nov 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion custom_components/yahoofinance/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -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. """

Expand Down
21 changes: 18 additions & 3 deletions custom_components/yahoofinance/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -122,7 +125,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

Expand Down Expand Up @@ -170,7 +176,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:
Expand Down Expand Up @@ -204,6 +214,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)

Expand All @@ -215,7 +226,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
Expand Down