NanmiCoder/MediaCrawler · error · ValueError
Invalid media platform: {platform!r}. Supported: {supported}
Error message
Invalid media platform: {platform!r}. Supported: {supported} What it means
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.
Source
Thrown at main.py:66
class CrawlerFactory:
CRAWLERS: dict[str, Type[AbstractCrawler]] = {
"xhs": XiaoHongShuCrawler,
"dy": DouYinCrawler,
"ks": KuaishouCrawler,
"bili": BilibiliCrawler,
"wb": WeiboCrawler,
"tieba": TieBaCrawler,
"zhihu": ZhihuCrawler,
}
@staticmethod
def create_crawler(platform: str) -> AbstractCrawler:
crawler_class = CrawlerFactory.CRAWLERS.get(platform)
if not crawler_class:
supported = ", ".join(sorted(CrawlerFactory.CRAWLERS))
raise ValueError(f"Invalid media platform: {platform!r}. Supported: {supported}")
return crawler_class()
crawler: Optional[AbstractCrawler] = None
def _flush_excel_if_needed() -> None:
if config.SAVE_DATA_OPTION != "excel":
return
try:
from store.excel_store_base import ExcelStoreBase
ExcelStoreBase.flush_all()
print("[Main] Excel files saved successfully")
except Exception as e:
print(f"[Main] Error flushing Excel data: {e}")
View on GitHub (pinned to d6f7c5bb90)
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.
Example fix
# before
CrawlerFactory.create_crawler('douyin')
# after
CrawlerFactory.create_crawler('dy') Defensive patterns
Strategy: type-guard
Validate before calling
from main import CrawlerFactory
platform = (platform or '').strip().lower()
if platform not in CrawlerFactory.CRAWLERS:
raise SystemExit(f'platform must be one of {sorted(CrawlerFactory.CRAWLERS)}') Type guard
def is_supported_platform(p: str) -> bool:
return isinstance(p, str) and p in {'xhs', 'dy', 'ks', 'bili', 'wb', 'tieba', 'zhihu'} Try / catch
try:
crawler = CrawlerFactory.create_crawler(platform)
except ValueError as e:
print(e) # message already lists supported platforms
sys.exit(2) Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Unknown cache type: {cache_type}
- Unsupported database type: {db_type}
- [BilibiliLogin.begin] Invalid Login Type Currently only supp
- [DouYinLogin.begin] Invalid Login Type Currently only suppor
- Wrong time range, please check your start and end argument,
AI-assisted analysis of NanmiCoder/MediaCrawler@d6f7c5bb90 (2026-08-15).
Data as JSON: /api/errors/08c9e469936628c0.
Report an issue: GitHub.