From f8f0d69e5c2f9c4a850c976f44dd91bb83a451c4 Mon Sep 17 00:00:00 2001 From: "2569718930@qq.com" <2569718930@qq.com> Date: Sat, 23 May 2026 01:04:01 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20AEROWEB=20Cookie=20?= =?UTF-8?q?=E6=8F=90=E5=8F=96=EF=BC=9Ahttpx=20session.cookies=20=E6=9B=BF?= =?UTF-8?q?=E4=BB=A3=20resp.cookies.jar?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit httpx 的 cookies API 与 requests 库不同,resp.cookies.jar 在 httpx 中不存在, 导致 PHPSESSID 提取失败、登录报错。改用 self.session.cookies.get() 直接读取。 --- src/data_collection/aeroweb_sources.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/data_collection/aeroweb_sources.py b/src/data_collection/aeroweb_sources.py index 33503ade..07f9fa68 100644 --- a/src/data_collection/aeroweb_sources.py +++ b/src/data_collection/aeroweb_sources.py @@ -60,15 +60,14 @@ class AerowebSourceMixin: try: # Step 1: get a fresh PHPSESSID - resp = self._http_get(f"{self.AEROWEB_BASE}/login.php", timeout=self.timeout) - # httpx follows redirects; grab PHPSESSID from the cookie jar - sid = None - for cookie in resp.cookies.jar: - if cookie.name == "PHPSESSID": - sid = cookie.value - break + # Use the shared httpx session so cookies persist across requests. + resp = self.session.get( + f"{self.AEROWEB_BASE}/login.php", timeout=self.timeout + ) + # httpx stores cookies on the session; grab PHPSESSID from there. + sid = self.session.cookies.get("PHPSESSID") if not sid: - # Try extracting from Set-Cookie header + # Fallback: parse Set-Cookie header directly set_cookie = resp.headers.get("set-cookie", "") for part in set_cookie.replace(",", ";").split(";"): part = part.strip()