tursodatabase/turso · error · ValueError

TursoSyncDialect does not support username/password in URL…

Error message

TursoSyncDialect does not support username/password in URL. Use auth_token query parameter or connect_args instead.

What it means

TursoSyncDialect validates the parsed URL before building connect arguments and rejects any URL that carries a username or password component. Sync credentials are never read from URL userinfo; the token must be supplied as the auth_token query parameter or through connect_args instead.

Solutions

  1. Remove user:pass from the URL
  2. Pass the token as a query parameter: sqlite+turso_sync:///local.db?auth_token=<token>
  3. Or pass it via connect_args: create_engine(url, connect_args={'auth_token': token})

Example fix

# before
engine = create_engine("sqlite+turso_sync://user:pass@/app.db")

# after
engine = create_engine("sqlite+turso_sync:///app.db?auth_token=<token>")
Defensive patterns

Strategy: validation

Validate before calling

from sqlalchemy.engine.url import make_url

url = make_url(database_url)
if url.username or url.password:
    auth_token = url.password or url.username
    database_url = url.set(username=None, password=None).render_as_string(hide_password=False)
    database_url += ("&" if "?" in database_url else "?") + f"auth_token={auth_token}"
engine = create_engine(database_url)

Try / catch

try:
    engine = create_engine(database_url)
except ValueError as e:
    if "username/password" in str(e):
        raise ValueError("Strip credentials from the URL; pass ?auth_token= instead") from e
    raise

Prevention

When it happens

Trigger: create_engine('sqlite+turso_sync://user:secret@/local.db') or a DATABASE_URL copied from a Postgres-style service that embeds user:pass in the authority section.

Common situations: Reusing a platform-injected DATABASE_URL that always contains credentials; tools that auto-prepend usernames into URLs; moving an app from Postgres to Turso sync without rewriting the URL scheme.

Related errors


AI-assisted analysis of tursodatabase/turso@244cde92a7 (2026-08-20). Data as JSON: /api/errors/f5889e3a52dc2358. Report an issue: GitHub.

Appendix: source

Thrown at bindings/python/turso/sqlalchemy/dialect.py:381

    @classmethod
    def import_dbapi(cls):
        """Import the turso.sync module as DBAPI."""
        import turso.sync

        return turso.sync

    def connect(self, *cargs, **cparams):
        """Remap sync_url to remote_url for libsql-sqlalchemy compatibility."""

        if "sync_url" in cparams and "remote_url" not in cparams:
            cparams["remote_url"] = cparams.pop("sync_url")
        return super().connect(*cargs, **cparams)

    @staticmethod
    def _validate_sync_url(opts: Dict[str, Any]) -> None:
        """Reject URL components that TursoSyncDialect doesn't support."""
        if opts.get("username") or opts.get("password"):
            raise ValueError(
                "TursoSyncDialect does not support username/password in URL. "
                "Use auth_token query parameter or connect_args instead."
            )
        if opts.get("host") or opts.get("port"):
            raise ValueError(
                "TursoSyncDialect does not support host/port in URL. "
                "The local database path goes after ':///', and remote_url "
                "is specified as a query parameter."
            )

    @staticmethod
    def _extract_sync_params(query_params: Dict[str, str]) -> Dict[str, Any]:
        """Extract and convert sync-specific query parameters into kwargs."""
        kwargs: Dict[str, Any] = {}

        auth_token = query_params.pop("auth_token", None)
        if auth_token:
            kwargs["auth_token"] = auth_token

View on GitHub (pinned to 244cde92a7)