Skip to content

Commit 188a96b

Browse files
committed
fix: switch Sina and Tencent endpoints to HTTPS
1 parent f9549c7 commit 188a96b

3 files changed

Lines changed: 25 additions & 14 deletions

File tree

data_provider/akshare_fetcher.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -931,17 +931,17 @@ def _get_stock_realtime_quote_sina(self, stock_code: str) -> Optional[UnifiedRea
931931
优点:单股票查询,负载小,速度快
932932
缺点:数据字段较少,无量比/PE/PB等
933933
934-
接口格式:http://hq.sinajs.cn/list=sh600519,sz000001
934+
接口格式:https://hq.sinajs.cn/list=sh600519,sz000001
935935
"""
936936
circuit_breaker = get_realtime_circuit_breaker()
937937
source_key = "akshare_sina"
938938
symbol = _to_sina_tx_symbol(stock_code)
939-
url = f"http://{SINA_REALTIME_ENDPOINT}={symbol}"
939+
url = f"https://{SINA_REALTIME_ENDPOINT}={symbol}"
940940
api_start = time.time()
941941

942942
try:
943943
headers = {
944-
'Referer': 'http://finance.sina.com.cn',
944+
'Referer': 'https://finance.sina.com.cn',
945945
'User-Agent': random.choice(USER_AGENTS)
946946
}
947947

@@ -1082,17 +1082,17 @@ def _get_stock_realtime_quote_tencent(self, stock_code: str) -> Optional[Unified
10821082
优点:单股票查询,负载小,包含换手率
10831083
缺点:无量比/PE/PB等估值数据
10841084
1085-
接口格式:http://qt.gtimg.cn/q=sh600519,sz000001
1085+
接口格式:https://qt.gtimg.cn/q=sh600519,sz000001
10861086
"""
10871087
circuit_breaker = get_realtime_circuit_breaker()
10881088
source_key = "akshare_tencent"
10891089
symbol = _to_sina_tx_symbol(stock_code)
1090-
url = f"http://{TENCENT_REALTIME_ENDPOINT}={symbol}"
1090+
url = f"https://{TENCENT_REALTIME_ENDPOINT}={symbol}"
10911091
api_start = time.time()
10921092

10931093
try:
10941094
headers = {
1095-
'Referer': 'http://finance.qq.com',
1095+
'Referer': 'https://finance.qq.com',
10961096
'User-Agent': random.choice(USER_AGENTS)
10971097
}
10981098

docs/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/).
1111

1212
<!-- 新条目格式:- [类型] 描述(类型取值:新功能/改进/修复/文档/测试/chore)-->
1313
<!-- 每条独立一行追加到本段末尾,无需分类标题,合并时冲突最小 -->
14+
- [修复] 将新浪 (Sina) 和腾讯 (Tencent) 实时行情接口切换至 HTTPS,提升数据传输安全性。
1415
- [改进] 放宽 LiteLLM 依赖约束,保留 `>=1.80.10` 最低版本并显式排除 PyPI 事故版本 `1.82.7` / `1.82.8`,允许安装后续 1.x 修复版本。
1516
- [改进] 补齐通知渠道 P0 基线、Actions 映射与 `--check-notify` 只读诊断,完善 AstrBot 配置入口和通知回归快照。
1617
- [chore] 清理仓库根目录:移除误入库的 `.codex``review.md` 跟踪记录,将 smoke 测试入口迁移到 `scripts/`、环境检查脚本迁移为 `scripts/check_env.py`,并将 LiteLLM YAML 示例迁移到 `docs/examples/`

tests/test_akshare_realtime_logging.py

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,16 +73,21 @@ def akshare_fetcher(monkeypatch):
7373

7474
def test_sina_realtime_success_logs_endpoint(caplog, monkeypatch, akshare_fetcher):
7575
breaker = _DummyCircuitBreaker()
76+
captured_url = None
77+
78+
def _mock_get(url, *args, **kwargs):
79+
nonlocal captured_url
80+
captured_url = url
81+
return _DummyResponse(200, _make_sina_payload())
82+
7683
monkeypatch.setattr("data_provider.akshare_fetcher.get_realtime_circuit_breaker", lambda: breaker)
77-
monkeypatch.setattr(
78-
"data_provider.akshare_fetcher.requests.get",
79-
lambda *args, **kwargs: _DummyResponse(200, _make_sina_payload()),
80-
)
84+
monkeypatch.setattr("data_provider.akshare_fetcher.requests.get", _mock_get)
8185

8286
with caplog.at_level(logging.INFO):
8387
quote = akshare_fetcher._get_stock_realtime_quote_sina("601006")
8488

8589
assert quote is not None
90+
assert captured_url.startswith("https://")
8691
assert quote.name == "大秦铁路"
8792
assert quote.price == 5.19
8893
assert breaker.successes == ["akshare_sina"]
@@ -133,16 +138,21 @@ def test_tencent_realtime_http_status_logs_endpoint(caplog, monkeypatch, akshare
133138

134139
def test_tencent_realtime_success_logs_endpoint(caplog, monkeypatch, akshare_fetcher):
135140
breaker = _DummyCircuitBreaker()
141+
captured_url = None
142+
143+
def _mock_get(url, *args, **kwargs):
144+
nonlocal captured_url
145+
captured_url = url
146+
return _DummyResponse(200, _make_tencent_payload())
147+
136148
monkeypatch.setattr("data_provider.akshare_fetcher.get_realtime_circuit_breaker", lambda: breaker)
137-
monkeypatch.setattr(
138-
"data_provider.akshare_fetcher.requests.get",
139-
lambda *args, **kwargs: _DummyResponse(200, _make_tencent_payload()),
140-
)
149+
monkeypatch.setattr("data_provider.akshare_fetcher.requests.get", _mock_get)
141150

142151
with caplog.at_level(logging.INFO):
143152
quote = akshare_fetcher._get_stock_realtime_quote_tencent("601006")
144153

145154
assert quote is not None
155+
assert captured_url.startswith("https://")
146156
assert quote.name == "大秦铁路"
147157
assert quote.price == 5.19
148158
assert breaker.successes == ["akshare_tencent"]

0 commit comments

Comments
 (0)