ZhuLinsen/daily_stock_analysis · error · ValueError
文本超过 KB 限制
Error message
文本超过 {MAX_TEXT_BYTES // 1024}KB 限制 What it means
Guard in parse_import_from_text: the UTF-8 byte length of the pasted text exceeds MAX_TEXT_BYTES (100KB). Measured on encoded bytes, not characters, so CJK-heavy text hits it sooner per character.
Solutions
- Paste only the code (and optionally name) column
- Split the paste into batches under 100KB each
- If the content is really a file, use the file upload path (2MB limit) instead
Example fix
# before
items = parse_import_from_text(huge_clipboard_text)
# after
lines = [ln for ln in huge_clipboard_text.splitlines() if ln.strip()]
items = []
for i in range(0, len(lines), 500):
items += parse_import_from_text('\n'.join(lines[i:i+500])) Defensive patterns
Strategy: validation
Validate before calling
from src.services.import_parser import MAX_TEXT_BYTES
if len(text.encode('utf-8')) > MAX_TEXT_BYTES:
text = '\n'.join(ln for ln in text.splitlines() if ln.strip() and looks_like_code_or_name(ln)) Type guard
def within_text_limit(t: str) -> bool:
return len(t.encode('utf-8')) <= 100 * 1024 Prevention
- Strip to the code/name column before pasting
- Split large pastes into sub-100KB batches
- Prefer file upload for very large lists (2MB allowance)
When it happens
Trigger: Pasting a huge clipboard (entire watchlist page, thousands of rows with names) into the text-import UI.
Common situations: Select-all paste from a large spreadsheet; pasting an entire webpage rather than the code column; clipboard containing a whole CSV file.
Related errors
- 文件超过 MB 限制
- CSV 解析失败:请检查分隔符是否一致、列数是否匹配。常见原因:引号未闭合、某行列数与其他行不一致。原始错误
- Excel 解析失败: 。请确认:(1) 文件为 .xlsx 格式;(2) 工作表不为空;(3) 文件未损坏。若为…
- file_too_large
- 加载 Futu OpenAPI SDK 失败
AI-assisted analysis of ZhuLinsen/daily_stock_analysis@5159bd72e8 (2026-08-15).
Data as JSON: /api/errors/99f5784c674a72bf.
Report an issue: GitHub.
Appendix: source
Thrown at src/services/import_parser.py:248
rows.append(parts)
if not rows:
return []
df = pd.DataFrame(rows)
return _parse_dataframe(df)
def parse_import_from_text(text: str) -> List[Tuple[Optional[str], Optional[str], str]]:
"""
Parse clipboard/text into items.
Args:
text: Raw text (e.g. from clipboard).
Returns:
List of (code, name, confidence).
"""
if len(text.encode("utf-8")) > MAX_TEXT_BYTES:
raise ValueError(f"文本超过 {MAX_TEXT_BYTES // 1024}KB 限制")
logger.debug(f"[ImportParser] 开始解析粘贴文本: bytes={len(text.encode('utf-8'))}")
data = text.encode("utf-8")
return parse_import_from_bytes(data, filename="paste.txt")
View on GitHub (pinned to 5159bd72e8)