microsoft/markitdown · error · ValueError

Not a data URI

Error message

Not a data URI

What it means

parse_data_uri() guards its contract: the input must literally start with 'data:' or it raises this bare ValueError. convert_uri() only invokes it after a startswith('data:') check, so the error surfaces only for direct calls on non-data URIs.

Source

Thrown at packages/markitdown/src/markitdown/_uri_utils.py:21

from typing import Tuple, Dict
from urllib.request import url2pathname
from urllib.parse import urlparse, unquote_to_bytes


def file_uri_to_path(file_uri: str) -> Tuple[str | None, str]:
    """Convert a file URI to a local file path"""
    parsed = urlparse(file_uri)
    if parsed.scheme != "file":
        raise ValueError(f"Not a file URL: {file_uri}")

    netloc = parsed.netloc if parsed.netloc else None
    path = os.path.abspath(url2pathname(parsed.path))
    return netloc, path


def parse_data_uri(uri: str) -> Tuple[str | None, Dict[str, str], bytes]:
    if not uri.startswith("data:"):
        raise ValueError("Not a data URI")

    header, _, data = uri.partition(",")
    if not _:
        raise ValueError("Malformed data URI, missing ',' separator")

    meta = header[5:]  # Strip 'data:'
    parts = meta.split(";")

    is_base64 = False
    # Ends with base64?
    if parts[-1] == "base64":
        parts.pop()
        is_base64 = True

    mime_type = None  # Normally this would default to text/plain but we won't assume
    if len(parts) and len(parts[0]) > 0:
        # First part is the mime type
        mime_type = parts.pop(0)

View on GitHub (pinned to fd239d5d2b)

Solutions

  1. Prefix the payload with 'data:' before parsing
  2. Route by scheme (startswith('data:')) before choosing parse_data_uri
  3. Prefer the public md.convert_uri(), which routes correctly

Example fix

# before
parse_data_uri("text/plain;base64,aGVsbG8=")  # ValueError

# after
parse_data_uri("data:text/plain;base64,aGVsbG8=")
Defensive patterns

Strategy: validation

Validate before calling

assert uri.startswith("data:")

Try / catch

from markitdown._uri_utils import parse_data_uri

try:
    mime, attrs, data = parse_data_uri(uri)
except ValueError as e:
    if "Not a data URI" in str(e):
        uri = "data:" + uri.lstrip("data:")  # normalize then retry once
        mime, attrs, data = parse_data_uri(uri)
    else:
        raise

Prevention

When it happens

Trigger: Calling parse_data_uri('file:///x') or parse_data_uri('text/plain;base64,AAA') (missing data: prefix) directly.

Common situations: Custom preprocessing that strips or mangles the scheme, or routing logic that forwards URIs to the wrong parser.

Related errors


AI-assisted analysis of microsoft/markitdown@fd239d5d2b (2026-08-14). Data as JSON: /api/errors/7cc45e125c0973c4. Report an issue: GitHub.