sansan0/TrendRadar · error · FileNotFoundError
频率词文件 {frequency_file} 不存在
Error message
频率词文件 {frequency_file} 不存在 What it means
Raised by the frequency-word loader when neither the configured frequency file path nor the fallback under config/custom/keyword/ exists. The loader resolves the path from the argument, then FREQUENCY_WORDS_PATH env var, then config/frequency_words.txt, and finally tries the short-name fallback before giving up with FileNotFoundError.
Source
Thrown at trendradar/core/frequency.py:134
Returns:
(词组列表, 词组内过滤词, 全局过滤词)
Raises:
FileNotFoundError: 频率词文件不存在
"""
if frequency_file is None:
frequency_file = os.environ.get(
"FREQUENCY_WORDS_PATH", "config/frequency_words.txt"
)
frequency_path = Path(frequency_file)
if not frequency_path.exists():
# 尝试作为短文件名,拼接 config/custom/keyword/ 前缀
custom_path = Path("config/custom/keyword") / frequency_file
if custom_path.exists():
frequency_path = custom_path
else:
raise FileNotFoundError(f"频率词文件 {frequency_file} 不存在")
with open(frequency_path, "r", encoding="utf-8") as f:
content = f.read()
word_groups = [group.strip() for group in content.split("\n\n") if group.strip()]
processed_groups = []
filter_words = []
global_filters = []
# 默认区域(向后兼容)
current_section = "WORD_GROUPS"
for group in word_groups:
# 过滤空行和注释行(# 开头)
lines = [line.strip() for line in group.split("\n") if line.strip() and not line.strip().startswith("#")]
if not lines:View on GitHub (pinned to 8ee26026ba)
Solutions
- Verify the file exists at the exact path in the error; create or restore it.
- If unset intentionally, ensure config/frequency_words.txt exists in the working directory, or set FREQUENCY_WORDS_PATH to an absolute path.
- For short filenames, place the file under config/custom/keyword/<name> so the fallback finds it.
- Run from the repository root so relative config paths resolve.
Example fix
# before: FREQUENCY_WORDS_PATH=/old/path/frequency_words.txt (file moved) # after: export FREQUENCY_WORDS_PATH=/abs/path/to/config/frequency_words.txt
Defensive patterns
Strategy: validation
Validate before calling
from pathlib import Path
def resolve_frequency_file(p=None):
cand = Path(p or os.environ.get("FREQUENCY_WORDS_PATH", "config/frequency_words.txt"))
if cand.exists():
return cand
alt = Path("config/custom/keyword") / cand.name
if alt.exists():
return alt
raise FileNotFoundError(f"frequency file missing: {cand} and {alt}")
freq = resolve_frequency_file() # call before load_frequency_words Try / catch
try:
words = load_frequency_words()
except FileNotFoundError as e:
logging.warning(f"{e}; falling back to default config/frequency_words.txt")
words = load_frequency_words("config/frequency_words.txt") Prevention
- Set FREQUENCY_WORDS_PATH to an absolute path in deployment.
- Include the frequency words file in deployment artifacts / setup scripts.
- Health-check required config files at process start.
When it happens
Trigger: Setting FREQUENCY_WORDS_PATH to a moved/renamed file; deleting config/frequency_words.txt without replacing it; running trendradar from a directory where the relative config path does not resolve (cwd not repo root).
Common situations: Fresh clone missing the config file (not committed or generated by setup); deployment where the service starts in a different cwd so relative 'config/frequency_words.txt' points nowhere; renaming a custom keyword file but leaving the env var stale.
Related errors
- 配置文件 {config_path} 不存在
- 不支持的传输模式: {transport}
- DATA_NOT_FOUND
- 不支持的模式: {mode}。支持的模式: daily, current
- CRAWL_TASK_ERROR
AI-assisted analysis of sansan0/TrendRadar@8ee26026ba (2026-08-15).
Data as JSON: /api/errors/fe0110847a703f92.
Report an issue: GitHub.