Revert proxy auth change — URL-embedded credentials are correct
Header-based auth made no difference; the real issue is the hotel network firewall blocking HTTPS CONNECT tunnels on port 823. Reverted to URL-embedded credentials (original approach). Fix requires DataImpulse to enable port 443. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
940ffbbe39
commit
28c4dd9f54
2 changed files with 18 additions and 22 deletions
|
|
@ -80,40 +80,35 @@ def username(cfg: dict, session_id: Optional[str] = None) -> str:
|
|||
def playwright_proxy(cfg: dict, session_id: Optional[str] = None) -> Optional[dict]:
|
||||
"""Proxy dict for new_context(proxy=...). None when disabled.
|
||||
|
||||
Uses separate username/password fields so Chromium sends a
|
||||
Proxy-Authorization header rather than embedding credentials in the URL.
|
||||
With IP whitelisting on DataImpulse, the 407 round-trip is skipped entirely
|
||||
(the proxy accepts on IP alone), so there is no speed penalty.
|
||||
Credentials are embedded in the server URL rather than passed as separate
|
||||
fields. Separate fields cause Chromium to wait for a 407 challenge before
|
||||
sending auth — DataImpulse takes ~14s to issue that challenge, making every
|
||||
page.goto() timeout. Embedded credentials are sent on the first CONNECT
|
||||
request, bypassing the round-trip entirely.
|
||||
"""
|
||||
if not is_enabled(cfg):
|
||||
return None
|
||||
from urllib.parse import quote
|
||||
user = quote(username(cfg, session_id), safe='')
|
||||
pwd = quote(cfg.get('password', ''), safe='')
|
||||
return {
|
||||
'server': f"http://{cfg['host']}:{cfg['port']}",
|
||||
'username': username(cfg, session_id),
|
||||
'password': cfg.get('password', ''),
|
||||
'server': f"http://{user}:{pwd}@{cfg['host']}:{cfg['port']}",
|
||||
}
|
||||
|
||||
|
||||
def httpx_proxy(cfg: dict, session_id: Optional[str] = None):
|
||||
"""httpx.Proxy object for AsyncClient(proxy=...). None when disabled.
|
||||
|
||||
Uses the auth= kwarg so credentials are sent as a Proxy-Authorization
|
||||
header rather than embedded in the URL.
|
||||
"""
|
||||
"""httpx.Proxy object for AsyncClient(proxy=...). None when disabled."""
|
||||
if not is_enabled(cfg):
|
||||
return None
|
||||
import httpx
|
||||
return httpx.Proxy(
|
||||
f"http://{cfg['host']}:{cfg['port']}",
|
||||
auth=(username(cfg, session_id), cfg.get('password', '')),
|
||||
)
|
||||
return httpx.Proxy(httpx_proxy_url(cfg, session_id))
|
||||
|
||||
|
||||
def httpx_proxy_url(cfg: dict, session_id: Optional[str] = None) -> Optional[str]:
|
||||
"""Legacy URL form — prefer httpx_proxy() for new callers."""
|
||||
"""Proxy URL for httpx.AsyncClient(proxy=...). None when disabled."""
|
||||
if not is_enabled(cfg):
|
||||
return None
|
||||
return f"http://{cfg['host']}:{cfg['port']}"
|
||||
return f"http://{username(cfg, session_id)}:{cfg.get('password', '')}@{cfg['host']}:{cfg['port']}"
|
||||
|
||||
|
||||
def direct_httpx_proxy(db):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue