Repository navigation
Add opt-in --browser-tls (curl_cffi) session to get past Cloudflare 403s (#4) - #9
Open
zenmonkey99 wants to merge 1 commit into
Open
zenmonkey99 wants to merge 1 commit into
zenmonkey99 wants to merge 1 commit into
Conversation
…erprint 403s Dominion's API host is behind Cloudflare bot protection that, from some networks, answers every request made with Python's TLS stack with an HTML "!! Error !! Access Denied" 403, authenticated or not. That is the failure in YeomansIII#4: login token exchange, token refresh and GetBpNumber all 403 with valid tokens. The same requests sent with a browser TLS fingerprint reach the API. - dompower/browser_session.py: BrowserSession, an adapter exposing the subset of aiohttp.ClientSession dompower uses (request/get/post as async context managers, cookie_jar) on top of curl_cffi's AsyncSession with browser impersonation. Works with DompowerClient and GigyaAuthenticator unchanged, including cookie save/load. - pyproject: optional extra dompower[browser] -> curl_cffi. - CLI: --browser-tls flag (or DOMPOWER_BROWSER_TLS=1) builds a BrowserSession for every command. - README: document the symptom and the flag. - tests: adapter behaviour with a fake curl session; Gigya cookie export/import through the adapter. Default behaviour is unchanged; aiohttp remains the default session. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KBfHz3wPHd66NetuAZxtiV
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #4.
Problem
From at least some residential networks (Verizon FiOS in Virginia here), Dominion's API host answers every request made from Python's TLS stack with an HTML
!! Error !! Access Deniedpage and HTTP 403, including unauthenticatedGET /. Sodompower logindies at the token exchange,refresh403s with valid tokens, andaccounts403s onGetBpNumber, exactly as reported in #4.Diagnosis:
GET /on prodsvc-dominioncip.smartcmobile.comserver: cloudflare)impersonate="chrome"It is Cloudflare's TLS-fingerprint bot rule, not headers or tokens. Other users evidently aren't hitting it, so this is opt-in.
Change
dompower/browser_session.py:BrowserSession, an adapter exposing the subset ofaiohttp.ClientSessiondompower uses (request/get/postas async context managers,cookie_jarwith iteration andupdate_cookies) on top ofcurl_cffi.requests.AsyncSessionwith browser impersonation.DompowerClientandGigyaAuthenticatorwork unchanged, including cookie save/load for TFA bypass.dompower[browser]pulling incurl_cffi. Default install and default behaviour are unchanged.--browser-tls(orDOMPOWER_BROWSER_TLS=1) usesBrowserSessionfor every command.Verification
dompower --browser-tls accounts,login(email 2FA, with Fix TFA verification for SMS and email (refreshed assertion + phvToken) #8 applied),refreshandusageall work against a real Dominion Virginia account. Without the flag the same commands still 403.pytest,ruff check,ruff format --check,mypy dompowerpass.Happy to make this the default, or to wire it into ha-dominion-energy behind a config option, if you'd prefer.
🤖 Generated with Claude Code
https://claude.ai/code/session_01KBfHz3wPHd66NetuAZxtiV