diff --git a/browser_login/login.py b/browser_login/login.py index bd9f535..7ca57a9 100644 --- a/browser_login/login.py +++ b/browser_login/login.py @@ -67,12 +67,13 @@ def patch_drission_ws_handshake() -> None: # Chrome 149 增强了 DevTools 的安全校验。 # Host header 必须是 IP 地址或 localhost,且必须包含端口号! + # 注意:websocket-client 会自动生成 Host 头,如果这里手动加上会导致发送重复的 Host 头,从而被 Chrome 500 拒绝。 candidate_kwargs = [ - # 策略1:最标准的 localhost 组合,带端口 + # 策略1:最标准的 localhost 组合,不手动加 Host 避免重复 { **base_kwargs, "suppress_origin": False, - "header": [f"Host: 127.0.0.1:{port}", "Origin: http://127.0.0.1"] + "header": ["Origin: http://127.0.0.1"] }, # 策略2:最原始、最干净的连接方式(类似 curl) { @@ -80,11 +81,11 @@ def patch_drission_ws_handshake() -> None: "suppress_origin": True, "header": [] }, - # 策略3:伪装成 localhost 带端口 + # 策略3:伪装成 localhost { **base_kwargs, "suppress_origin": False, - "header": [f"Host: localhost:{port}", "Origin: http://localhost"] + "header": ["Origin: http://localhost"] } ]