fix(datasource): 修复 zstd 响应 JSON 解析问题
- flask_api_source.py: 添加 requests.exceptions.JSONDecodeError 捕获 - flask_server.py: 启用 flask-compress gzip 压缩 - requirements.txt: 添加 flask-compress>=1.14 - strategy.py: 修复 flask_api 配置读取方式 问题原因:Traefik Ingress 使用 zstd 压缩响应, requests.response.json() 解析失败,但 json.loads(response.text) 成功
This commit is contained in:
@@ -109,7 +109,12 @@ class FlaskAPIDataSource:
|
||||
print(f"✗ API请求失败: {response.status_code} - {response.text[:100]}")
|
||||
return None
|
||||
|
||||
data = response.json()
|
||||
# 尝试解析 JSON(支持 zstd 响应)
|
||||
try:
|
||||
data = response.json()
|
||||
except (json.JSONDecodeError, requests.exceptions.JSONDecodeError):
|
||||
# 如果 response.json() 失败,手动解析
|
||||
data = json.loads(response.text)
|
||||
|
||||
# 检查错误
|
||||
if 'error' in data:
|
||||
|
||||
@@ -40,6 +40,7 @@ load_dotenv()
|
||||
|
||||
from flask import Flask, request, jsonify
|
||||
from flask_cors import CORS
|
||||
from flask_compress import Compress
|
||||
import pandas as pd
|
||||
|
||||
from datasource.universal_fetcher import UniversalDataFetcher
|
||||
@@ -52,6 +53,7 @@ from datasource.asset_type_detector import AssetTypeDetector, AssetType
|
||||
|
||||
app = Flask(__name__)
|
||||
CORS(app) # 启用跨域支持
|
||||
Compress(app) # 启用 gzip 压缩
|
||||
|
||||
# 全局数据获取器实例
|
||||
fetcher: Optional[UniversalDataFetcher] = None
|
||||
|
||||
Reference in New Issue
Block a user