{"record":{"id":"1b84fb1d80c8873a","repo":"harry0703/MoneyPrinterTurbo","slug":"n-n-cfg-key-is-not-set-n-nplease-set","errorCode":null,"errorMessage":"\\n\\n##### {cfg_key} is not set #####\\n\\nPlease set it in the config.toml file: {config.config_file}\\n","messagePattern":"\\\\n\\\\n##### (.+?) is not set #####\\\\n\\\\nPlease set it in the config\\.toml file: (.+?)\\\\n","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"app/services/material.py","lineNumber":160,"sourceCode":"    # 仅在企业代理、自签证书等明确需要的场景下，允许用户通过\n    # `config.toml` 显式设置 `tls_verify = false` 临时关闭。\n    tls_verify = config.app.get(\"tls_verify\", True)\n    if isinstance(tls_verify, str):\n        tls_verify = tls_verify.strip().lower() not in (\"0\", \"false\", \"no\", \"off\")\n\n    if not tls_verify:\n        logger.warning(\n            \"TLS certificate verification is disabled by config.app.tls_verify=false. \"\n            \"Only use this in trusted proxy environments.\"\n        )\n\n    return bool(tls_verify)\n\n\ndef get_api_key(cfg_key: str):\n    api_keys = config.app.get(cfg_key)\n    if not api_keys:\n        raise ValueError(\n            f\"\\n\\n##### {cfg_key} is not set #####\\n\\n\"\n            f\"Please set it in the config.toml file: {config.config_file}\\n\"\n        )\n\n    # if only one key is provided, return it\n    if isinstance(api_keys, str):\n        return api_keys\n\n    global _api_key_counter\n    with _api_key_lock:\n        _api_key_counter += 1\n        return api_keys[_api_key_counter % len(api_keys)]\n\n\ndef _redact_secret(message: str, secret: str) -> str:\n    \"\"\"\n    对即将写入日志的异常文本做最小范围脱敏。\n","sourceCodeStart":142,"sourceCodeEnd":178,"githubUrl":"https://github.com/harry0703/MoneyPrinterTurbo/blob/1f9f19c2021a68d04df228f33e9099a0c947f6f8/app/services/material.py#L142-L178","documentation":"Raised by get_api_key() in app/services/material.py when config.app.get(cfg_key) (e.g. 'pexels_api_keys' or 'pixabay_api_keys') is falsy. It is a pure configuration guard before any request: no stock-footage API key is configured, so material search/download cannot proceed. The message embeds the config.toml path for immediate action.","triggerScenarios":"Calling material search/subscribe functions with neither [app].pexels_api_keys nor pixabay_api_keys (whichever cfg_key is requested) set in config.toml — empty section, key commented out, or WebUI saved empty value.","commonSituations":"Fresh install without completing config.toml; user only configured llm_provider and video-source keys but forgot the material stock keys; renamed/misplaced keys (key must match cfg_key exactly, e.g. plural 'pexels_api_keys'); config.toml syntax error making the section unparseable so .get returns None.","solutions":["Open the config.toml file shown in the message and add the missing key, e.g. pexels_api_keys = [\"YOUR_KEY\"] under [app]","Get the key from the matching provider (Pexels/Pixabay developer portal) — both are free","Support a list for round-robin: pexels_api_keys = [\"key1\", \"key2\"] rotates via _api_key_counter","Validate config.toml parses (correct section header [app], no TOML syntax errors) after editing"],"exampleFix":"# before (config.toml)\n[app]\n# pexels_api_keys missing -> ValueError: ##### pexels_api_keys is not set #####\n\n# after\n[app]\npexels_api_keys = [\"xxxxxxxxxxxxxxxxxxxxxxxx\"]\npixabay_api_keys = [\"yyyyyyyyyyyyyyyyyyyyyyyy\"]","handlingStrategy":"validation","validationCode":"from app.config import config\n\ndef has_api_key(cfg_key: str) -> bool:\n    return bool(config.app.get(cfg_key))\n\nassert has_api_key('pexels_api_keys') or has_api_key('pixabay_api_keys'), \\\n    'configure at least one stock-footage key'","typeGuard":null,"tryCatchPattern":"except ValueError as e: if 'is not set' in str(e): non-retryable — prompt the user to edit config.toml at the path embedded in the message","preventionTips":["Fill every *_api_keys entry in config.toml at setup time","Validate config completeness at app startup, listing all missing keys at once","Keep config.toml.example in sync when new keys are introduced"],"tags":["configuration","material","stock-footage","config-toml","validation"],"backgroundTag":null,"analyzedSha":"1f9f19c2021a68d04df228f33e9099a0c947f6f8","analyzedAt":"2026-08-14T19:41:05.568Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}