diff --git a/data_platform/updater.py b/data_platform/updater.py index 65c239d3..818c9b42 100644 --- a/data_platform/updater.py +++ b/data_platform/updater.py @@ -81,13 +81,15 @@ def fetch_incremental(code: str, start_date: str, end_date: str): # 2. 腾讯K线API try: + import urllib.request, json prefix = 'sh' if code.startswith(('6', '5', '1')) else 'sz' tq = f"{prefix}{code}" days = (pd.Timestamp(end_date) - pd.Timestamp(start_date)).days + 10 url = f"https://web.ifzq.gtimg.cn/appstock/app/fqkline/get?param={tq},day,,{days}," - import urllib.request, json + # 用无代理opener避免akshare代理污染 + opener = urllib.request.build_opener(urllib.request.ProxyHandler({})) req = urllib.request.Request(url, headers={"User-Agent": "Mozilla/5.0"}) - with urllib.request.urlopen(req, timeout=10) as r: + with opener.open(req, timeout=10) as r: data = json.loads(r.read()) klines = data.get("data", {}).get(tq, {}).get("day", []) if not klines: