NanmiCoder/MediaCrawler · error · ValueError
Unsupported database type: {db_type}
Error message
Unsupported database type: {db_type} What it means
ValueError from database/db_session.py get_async_engine when db_type matches none of the supported backends: cached engines, the file-based trio ['json','jsonl','csv'] (which return None), 'sqlite', 'mysql'/'db', or 'postgres'. The string is used both to build the SQLAlchemy async URL and to select the engine, so an unknown value cannot be mapped to a driver.
Source
Thrown at database/db_session.py:70
def get_async_engine(db_type: str = None):
if db_type is None:
db_type = config.SAVE_DATA_OPTION
if db_type in _engines:
return _engines[db_type]
if db_type in ["json", "jsonl", "csv"]:
return None
if db_type == "sqlite":
db_url = f"sqlite+aiosqlite:///{sqlite_db_config['db_path']}"
elif db_type == "mysql" or db_type == "db":
db_url = f"mysql+asyncmy://{mysql_db_config['user']}:{mysql_db_config['password']}@{mysql_db_config['host']}:{mysql_db_config['port']}/{mysql_db_config['db_name']}"
elif db_type == "postgres":
db_url = f"postgresql+asyncpg://{postgres_db_config['user']}:{postgres_db_config['password']}@{postgres_db_config['host']}:{postgres_db_config['port']}/{postgres_db_config['db_name']}"
else:
raise ValueError(f"Unsupported database type: {db_type}")
engine = create_async_engine(db_url, echo=False)
_engines[db_type] = engine
return engine
async def create_tables(db_type: str = None):
if db_type is None:
db_type = config.SAVE_DATA_OPTION
await create_database_if_not_exists(db_type)
engine = get_async_engine(db_type)
if engine:
async with engine.begin() as conn:
await conn.run_sync(Base.metadata.create_all)
@asynccontextmanager
async def get_session() -> AsyncSession:View on GitHub (pinned to d6f7c5bb90)
Solutions
- Set db_type/SAVE_DATA_OPTION to one of the exact literals: 'sqlite', 'mysql' (or 'db'), 'postgres', or 'json'/'jsonl'/'csv'.
- For MongoDB use the project's MongoDB store path rather than get_async_engine, which only builds SQL engines.
- Use the literal 'postgres', not 'postgresql', for the URL branch to match.
- Validate the config value at startup and fail fast with the list of supported types.
Example fix
# before
get_async_engine('postgresql')
# after
get_async_engine('postgres') Defensive patterns
Strategy: type-guard
Validate before calling
SUPPORTED = {'sqlite', 'mysql', 'db', 'postgres', 'json', 'jsonl', 'csv'}
if db_type not in SUPPORTED:
raise SystemExit(f'db type must be one of {sorted(SUPPORTED)}, got {db_type!r}') Type guard
def is_supported_db(t: str) -> bool:
return isinstance(t, str) and t in {'sqlite', 'mysql', 'db', 'postgres', 'json', 'jsonl', 'csv'} Try / catch
try:
engine = get_async_engine(db_type)
except ValueError as e:
logger.error(f'unsupported db {db_type!r}: {e}')
raise SystemExit(2) Prevention
- Use the literal 'postgres' (not 'postgresql') and lowercase values
- Validate SAVE_DATA_OPTION before the async engine is created
- Remember 'json'/'jsonl'/'csv' return None engines by design — handle that downstream
When it happens
Trigger: SAVE_DATA_OPTION / db_type set to a typo ('mongo' is handled elsewhere as a document store but not by this engine function, 'postgresql' instead of 'postgres', 'MySQL' capitalized); passing a backend name that only exists in a different version of the project.
Common situations: Editing SAVE_DATA_OPTION in config/base_config.py; adding a new storage backend without touching db_session; case-sensitive literals ('sqlite' vs 'SQLite') copied from docs.
Related errors
- Unknown cache type: {cache_type}
- Invalid media platform: {platform!r}. Supported: {supported}
- [BilibiliLogin.begin] Invalid Login Type Currently only supp
- [DouYinLogin.begin] Invalid Login Type Currently only suppor
- Unknown proxy provider: '{config.IP_PROXY_PROVIDER_NAME}'. V
AI-assisted analysis of NanmiCoder/MediaCrawler@d6f7c5bb90 (2026-08-15).
Data as JSON: /api/errors/1b99356bfded5b80.
Report an issue: GitHub.