From 84a01fb7b136b99a8e520b8274472b7c4ed05618 Mon Sep 17 00:00:00 2001 From: Sakurasan <26715255+Sakurasan@users.noreply.github.com> Date: Mon, 10 Aug 2026 18:36:27 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=A1=A5=E9=BD=90=E5=AE=8C=E6=95=B4?= =?UTF-8?q?=E6=B5=8F=E8=A7=88=E5=99=A8=E8=AF=B7=E6=B1=82=E5=A4=B4=E5=B9=B6?= =?UTF-8?q?=E6=94=B9=E7=94=A8=20web=20client=EF=BC=8C=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E7=94=9F=E4=BA=A7=20403=20=E6=8B=BF=E4=B8=8D=E5=88=B0=E9=A2=98?= =?UTF-8?q?=E6=9D=90=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 生产服务器请求东财题材列表/相关股票返回 403(缺 sec-* 头 + iOS client 被风控识别为爬虫),导致热点穿透重建失败、数据冻结在上个交易日。 - 请求头补齐 sec-ch-ua/sec-fetch-*/priority/dnt 等完整 Chrome 头 - payload client 由 iOS 改为 web(生产实测该组合正常返回) - content-type 补 charset=UTF-8 生产实测:完整头 + web client 正常返回数据。 Co-Authored-By: Claude --- backend/services/themes.py | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/backend/services/themes.py b/backend/services/themes.py index e9380b8..e66290e 100644 --- a/backend/services/themes.py +++ b/backend/services/themes.py @@ -30,12 +30,23 @@ _PZ_CDN_URL = "https://emcfgdata.securities.eastmoney.com" _APP_KEY_INDEX = "rn-themeIndex" _APP_KEY_DETAIL = "rn-themeDetail" +# 完整浏览器请求头:生产实测东财对缺 sec-* 头的移动端包装结构请求会 403, +# 补齐真实 Chrome 头 + client="web" 后正常返回 _HEADERS = { - "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36", - "Origin": "https://emrnweb.eastmoney.com", - "Referer": "https://emrnweb.eastmoney.com/", - "Accept": "application/json", + "Accept": "application/json, text/plain, */*", "Accept-Language": "zh-CN,zh;q=0.9", + "Content-Type": "application/json;charset=UTF-8", + "DNT": "1", + "Origin": "https://emrnweb.eastmoney.com", + "Priority": "u=1, i", + "Referer": "https://emrnweb.eastmoney.com/", + "Sec-Ch-Ua": '"Not=A?Brand";v="99", "Google Chrome";v="151", "Chromium";v="151"', + "Sec-Ch-Ua-Mobile": "?0", + "Sec-Ch-Ua-Platform": '"macOS"', + "Sec-Fetch-Dest": "empty", + "Sec-Fetch-Mode": "cors", + "Sec-Fetch-Site": "same-site", + "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/151.0.0.0 Safari/537.36", } # ---- 交易时段感知缓存 ---- @@ -89,7 +100,7 @@ def _build_payload(args: Optional[dict] = None, app_key: str = _APP_KEY_INDEX) - return { "args": args or {}, "appKey": app_key, - "client": "iOS", + "client": "web", # 生产实测 iOS client 会 403,web + 完整浏览器头正常 "clientVersion": "8.3", "clientType": "cfw", "randomCode": "".join(random.choices(string.ascii_uppercase + string.ascii_lowercase + string.digits, k=16)),