{"record":{"id":"08c9e469936628c0","repo":"NanmiCoder/MediaCrawler","slug":"invalid-media-platform-platform-r-supported","errorCode":null,"errorMessage":"Invalid media platform: {platform!r}. Supported: {supported}","messagePattern":"Invalid media platform: (.+?)\\. Supported: (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"main.py","lineNumber":66,"sourceCode":"\n\nclass CrawlerFactory:\n    CRAWLERS: dict[str, Type[AbstractCrawler]] = {\n        \"xhs\": XiaoHongShuCrawler,\n        \"dy\": DouYinCrawler,\n        \"ks\": KuaishouCrawler,\n        \"bili\": BilibiliCrawler,\n        \"wb\": WeiboCrawler,\n        \"tieba\": TieBaCrawler,\n        \"zhihu\": ZhihuCrawler,\n    }\n\n    @staticmethod\n    def create_crawler(platform: str) -> AbstractCrawler:\n        crawler_class = CrawlerFactory.CRAWLERS.get(platform)\n        if not crawler_class:\n            supported = \", \".join(sorted(CrawlerFactory.CRAWLERS))\n            raise ValueError(f\"Invalid media platform: {platform!r}. Supported: {supported}\")\n        return crawler_class()\n\n\ncrawler: Optional[AbstractCrawler] = None\n\n\ndef _flush_excel_if_needed() -> None:\n    if config.SAVE_DATA_OPTION != \"excel\":\n        return\n\n    try:\n        from store.excel_store_base import ExcelStoreBase\n\n        ExcelStoreBase.flush_all()\n        print(\"[Main] Excel files saved successfully\")\n    except Exception as e:\n        print(f\"[Main] Error flushing Excel data: {e}\")\n","sourceCodeStart":48,"sourceCodeEnd":84,"githubUrl":"https://github.com/NanmiCoder/MediaCrawler/blob/d6f7c5bb906b6dac40ddf343ef9e26438a3de092/main.py#L48-L84","documentation":"ValueError from CrawlerFactory.create_crawler (main.py) when the platform key is not in the CRAWLERS registry ('xhs','dy','ks','bili','wb','tieba','zhihu'). The factory looks up the platform string in a dict and this error enumerates the accepted short codes, so the message doubles as built-in documentation.","triggerScenarios":"Running the CLI with an unsupported platform code, e.g. --platform抖音, 'douyin' instead of 'dy', 'weibo' vs 'wb', 'bilibili' vs 'bili'; passing an empty platform when no default was configured.","commonSituations":"Typing full platform names instead of the short aliases; a new platform crawler added to media_platform/ but not registered in CrawlerFactory.CRAWLERS; scripts that pass platform names from external data without normalizing.","solutions":["Use one of the short codes printed in the error itself: xhs, dy, ks, bili, wb, tieba, zhihu.","Normalize user input (strip/lower, map full names to codes) before calling create_crawler.","If adding a platform, register its class in CrawlerFactory.CRAWLERS at main.py."],"exampleFix":"# before\nCrawlerFactory.create_crawler('douyin')\n\n# after\nCrawlerFactory.create_crawler('dy')","handlingStrategy":"type-guard","validationCode":"from main import CrawlerFactory\nplatform = (platform or '').strip().lower()\nif platform not in CrawlerFactory.CRAWLERS:\n    raise SystemExit(f'platform must be one of {sorted(CrawlerFactory.CRAWLERS)}')","typeGuard":"def is_supported_platform(p: str) -> bool:\n    return isinstance(p, str) and p in {'xhs', 'dy', 'ks', 'bili', 'wb', 'tieba', 'zhihu'}","tryCatchPattern":"try:\n    crawler = CrawlerFactory.create_crawler(platform)\nexcept ValueError as e:\n    print(e)  # message already lists supported platforms\n    sys.exit(2)","preventionTips":["Normalize input: strip, lowercase, map full names to codes (douyin->dy)","Register new platforms in CrawlerFactory.CRAWLERS when adding crawlers","Read the error message — it enumerates every supported code"],"tags":["cli","configuration","valueerror","factory","platform-selection"],"backgroundTag":null,"analyzedSha":"d6f7c5bb906b6dac40ddf343ef9e26438a3de092","analyzedAt":"2026-08-15T01:39:07.505Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}