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
|
|
@ -277,13 +277,14 @@ async def test_proxy_config(
|
||||||
'password': (raw.get('booking_proxy_password') or '').strip(),
|
'password': (raw.get('booking_proxy_password') or '').strip(),
|
||||||
'country': (raw.get('booking_proxy_country') or 'gb').strip(),
|
'country': (raw.get('booking_proxy_country') or 'gb').strip(),
|
||||||
}
|
}
|
||||||
if not proxy_util.is_enabled(cfg):
|
if not (proxy_util.is_enabled(cfg) and cfg['password']):
|
||||||
raise HTTPException(status_code=400, detail="Proxy host and username must be saved first.")
|
raise HTTPException(status_code=400, detail="Proxy host, username and password must be saved first.")
|
||||||
|
|
||||||
|
proxy_url = proxy_util.httpx_proxy_url(cfg, proxy_util.new_session_id())
|
||||||
|
|
||||||
import httpx
|
import httpx
|
||||||
proxy = proxy_util.httpx_proxy(cfg, proxy_util.new_session_id())
|
|
||||||
try:
|
try:
|
||||||
async with httpx.AsyncClient(proxy=proxy, timeout=40.0) as client:
|
async with httpx.AsyncClient(proxy=proxy_url, timeout=40.0) as client:
|
||||||
resp = await client.get("https://ipinfo.io/json")
|
resp = await client.get("https://ipinfo.io/json")
|
||||||
resp.raise_for_status()
|
resp.raise_for_status()
|
||||||
data = resp.json()
|
data = resp.json()
|
||||||
|
|
|
||||||
|
|
@ -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]:
|
def playwright_proxy(cfg: dict, session_id: Optional[str] = None) -> Optional[dict]:
|
||||||
"""Proxy dict for new_context(proxy=...). None when disabled.
|
"""Proxy dict for new_context(proxy=...). None when disabled.
|
||||||
|
|
||||||
Uses separate username/password fields so Chromium sends a
|
Credentials are embedded in the server URL rather than passed as separate
|
||||||
Proxy-Authorization header rather than embedding credentials in the URL.
|
fields. Separate fields cause Chromium to wait for a 407 challenge before
|
||||||
With IP whitelisting on DataImpulse, the 407 round-trip is skipped entirely
|
sending auth — DataImpulse takes ~14s to issue that challenge, making every
|
||||||
(the proxy accepts on IP alone), so there is no speed penalty.
|
page.goto() timeout. Embedded credentials are sent on the first CONNECT
|
||||||
|
request, bypassing the round-trip entirely.
|
||||||
"""
|
"""
|
||||||
if not is_enabled(cfg):
|
if not is_enabled(cfg):
|
||||||
return None
|
return None
|
||||||
|
from urllib.parse import quote
|
||||||
|
user = quote(username(cfg, session_id), safe='')
|
||||||
|
pwd = quote(cfg.get('password', ''), safe='')
|
||||||
return {
|
return {
|
||||||
'server': f"http://{cfg['host']}:{cfg['port']}",
|
'server': f"http://{user}:{pwd}@{cfg['host']}:{cfg['port']}",
|
||||||
'username': username(cfg, session_id),
|
|
||||||
'password': cfg.get('password', ''),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def httpx_proxy(cfg: dict, session_id: Optional[str] = None):
|
def httpx_proxy(cfg: dict, session_id: Optional[str] = None):
|
||||||
"""httpx.Proxy object for AsyncClient(proxy=...). None when disabled.
|
"""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.
|
|
||||||
"""
|
|
||||||
if not is_enabled(cfg):
|
if not is_enabled(cfg):
|
||||||
return None
|
return None
|
||||||
import httpx
|
import httpx
|
||||||
return httpx.Proxy(
|
return httpx.Proxy(httpx_proxy_url(cfg, session_id))
|
||||||
f"http://{cfg['host']}:{cfg['port']}",
|
|
||||||
auth=(username(cfg, session_id), cfg.get('password', '')),
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def httpx_proxy_url(cfg: dict, session_id: Optional[str] = None) -> Optional[str]:
|
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):
|
if not is_enabled(cfg):
|
||||||
return None
|
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):
|
def direct_httpx_proxy(db):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue