fix(data): ak-weekly 断路器饿死修复=_safe_northbound_em+类型调序 [vps]——09-05 03:00 首跑 rc=2 根因:akshare stock_hsgt_individual_em 对无北向数据标的(~1117/2883,301xxx 等)在 data_json[result][pages] 抛 TypeError NoneType not subscriptable→failed→30 连败断路器→跳过后续类型,share_capital/top_holders/gdhs 全饿死(gdhs 目录至今不存在);端点健康(600519 返 1683 行,09-06 晨复测);修=①_safe_northbound_em 子串匹配 not subscriptable 返空 df 带 9 列 schema→走无北向持仓 empty 写空+done 既定语义不耗重试/断路器(同 _safe_top_10_em 手法)②weekly wrapper 调序 gdhs,share_capital,top_holders,northbound 最大最险者殿后防再连累③顺手 BOM;TDD 2 新测先红后绿+217 全绿;双脚本已 scp 生效位+Parse/py_compile 预检过;gdhs 手动补跑另行 [vps]
CI/CD / test (push) Successful in 23s
CI/CD / nas-deploy (push) Successful in 7s
CI/CD / nas-verify (push) Successful in 13s

This commit is contained in:
2026-09-06 08:29:58 +08:00
parent c728f2368c
commit 694a0d2238
3 changed files with 73 additions and 5 deletions
@@ -496,10 +496,44 @@ def fetch_valuation(symbol: str) -> Optional[pd.DataFrame]:
return df
NORTHBOUND_COLUMNS = [
"持股日期", "当日收盘价", "当日涨跌幅", "持股数量", "持股市值",
"持股数量占A股百分比", "今日增持股数", "今日增持资金", "今日持股市值变化",
]
def _safe_northbound_em(symbol: str) -> pd.DataFrame:
"""akshare stock_hsgt_individual_em 包装: 容忍无北向数据标的的崩溃响应。
bug 根因 (实证 akshare 1.18.x stock_hsgt_em.py:1446, 2026-09-05 ak-weekly
断路器事故): 无北向数据标的 (301xxx 等 ~1117/2883) datacenter 返
result=None, __stock_hsgt_zh_a_em 的 data_json["result"]["pages"] 抛
TypeError("'NoneType' object is not subscriptable") → failed → 30 连败
断路器 rc=2, 饿死后续 share_capital/top_holders/gdhs。端点健康
(600519 正常返 1683 行)。
子串匹配 "not subscriptable" (稳定签名, 同 _safe_top_10_em 手法):
→ 返空 df (带 NORTHBOUND_COLUMNS schema), 走「无北向持仓」empty
写空+done (脚本头部既定语义), 不消耗重试/断路器配额;
其他 TypeError 透传给 call_ak_with_retry 走重试。
"""
try:
return ak.stock_hsgt_individual_em(symbol=symbol)
except TypeError as e:
if "not subscriptable" in str(e):
logger.debug(
"stock_hsgt_individual_em(%s) → 空 (无北向数据), 返空 df", symbol)
return pd.DataFrame(columns=NORTHBOUND_COLUMNS)
raise
def fetch_northbound(symbol: str) -> Optional[pd.DataFrame]:
"""stock_hsgt_individual_em(symbol='600519') — 北向持股 (~1700行/股)。"""
"""stock_hsgt_individual_em(symbol='600519') — 北向持股 (~1700行/股)。
通过 _safe_northbound_em 包装: 无北向数据标的 akshare 抛 NoneType
not subscriptable, 捕获返空 df (empty 语义, 不耗断路器配额)。"""
df, _status = call_ak_with_retry(
ak.stock_hsgt_individual_em, f"northbound/{symbol}", symbol=symbol,
_safe_northbound_em, f"northbound/{symbol}", symbol=symbol,
)
return df