NanmiCoder/MediaCrawler · error · ValueError

[KuaishouStoreFactory.create_store] Invalid save option only

Error message

[KuaishouStoreFactory.create_store] Invalid save option only supported csv or db or json or sqlite or mongodb or excel ...

What it means

Raised by KuaishouStoreFactory.create_store() when config.SAVE_DATA_OPTION is not found in the kuaishou STORES registry (csv, db, postgres, json, jsonl, sqlite, mongodb, excel). Startup-time guard preventing a kuaishou crawl from running with an unimplemented persistence backend.

Source

Thrown at store/kuaishou/__init__.py:50


class KuaishouStoreFactory:
    STORES = {
        "csv": KuaishouCsvStoreImplement,
        "db": KuaishouDbStoreImplement,
        "postgres": KuaishouDbStoreImplement,
        "json": KuaishouJsonStoreImplement,
        "jsonl": KuaishouJsonlStoreImplement,
        "sqlite": KuaishouSqliteStoreImplement,
        "mongodb": KuaishouMongoStoreImplement,
        "excel": KuaishouExcelStoreImplement,
    }

    @staticmethod
    def create_store() -> AbstractStore:
        store_class = KuaishouStoreFactory.STORES.get(config.SAVE_DATA_OPTION)
        if not store_class:
            raise ValueError(
                "[KuaishouStoreFactory.create_store] Invalid save option only supported csv or db or json or sqlite or mongodb or excel ...")
        return store_class()


async def update_kuaishou_video(video_item: Dict):
    photo_info: Dict = video_item.get("photo", {})
    video_id = photo_info.get("id")
    if not video_id:
        return
    user_info = video_item.get("author", {})
    save_content_item = {
        "video_id": video_id,
        "video_type": str(video_item.get("type")),
        "title": photo_info.get("caption", "")[:500],
        "desc": photo_info.get("caption", "")[:500],
        "create_time": photo_info.get("timestamp"),
        "creator_hash": anonymize_user_id(user_info.get("id")),  # 创作者匿名哈希(不存原始 user_id)
        "nickname": mask_nickname(user_info.get("name")),  # 用户昵称(已脱敏)

View on GitHub (pinned to d6f7c5bb90)

Solutions

  1. Set SAVE_DATA_OPTION to a registered key: csv, db, postgres, json, jsonl, sqlite, mongodb, excel
  2. Remember the option is global — changing it for kuaishou changes it for every platform factory
  3. Validate the config early: assert config.SAVE_DATA_OPTION in expected set at app start rather than failing mid-crawl
  4. For quick local runs use 'json' or 'sqlite' (no external services needed)

Example fix

// before
SAVE_DATA_OPTION = "MySQL"

// after
SAVE_DATA_OPTION = "db"  # exact, lowercase registry key
Defensive patterns

Strategy: validation

Validate before calling

from store.kuaishou import KuaishouStoreFactory

if config.SAVE_DATA_OPTION not in KuaishouStoreFactory.STORES:
    raise SystemExit(
        f"SAVE_DATA_OPTION={config.SAVE_DATA_OPTION!r} invalid; "
        f"choose from {sorted(KuaishouStoreFactory.STORES)}"
    )

Type guard

def is_valid_save_option(opt: str) -> bool:
    return isinstance(opt, str) and opt in KuaishouStoreFactory.STORES

Try / catch

try:
    store = KuaishouStoreFactory.create_store()
except ValueError as e:
    raise SystemExit(f"fix config before crawling: {e}") from e

Prevention

When it happens

Trigger: SAVE_DATA_OPTION contains a value like 'mysql', 'xlsx', or any string outside the registry; raised on the first store instantiation when the kuaishou crawler begins persisting results.

Common situations: Config edited for one platform's docs but reused globally (SAVE_DATA_OPTION is shared across all platforms); typo or uppercase value; value valid in an older project version.

Related errors


AI-assisted analysis of NanmiCoder/MediaCrawler@d6f7c5bb90 (2026-08-15). Data as JSON: /api/errors/122aaa51a755e5c7. Report an issue: GitHub.