PaddlePaddle/PaddleOCR · error · ValueError
Invalid data URL: expected a comma after the MIME type.
Error message
Invalid data URL: expected a comma after the MIME type.
What it means
ValueError from extract_base64_payload in paddleocr_mcp/utils.py when an input starts with `data:` but contains no comma. Data URLs must look like `data:<mime>;base64,<payload>`; the function splits on the first comma, so a missing comma means the MIME header was never terminated.
Source
Thrown at mcp_server/paddleocr_mcp/utils.py:41
def is_url(value: str) -> bool:
if not (value.startswith("http://") or value.startswith("https://")):
return False
result = urlparse(value)
return all([result.scheme, result.netloc]) and result.scheme in ("http", "https")
def is_base64(value: str) -> bool:
pattern = r"^[A-Za-z0-9+/]+={0,2}$"
return bool(re.fullmatch(pattern, value))
def extract_base64_payload(input_data: str) -> str:
if input_data.startswith("data:"):
if "," not in input_data:
raise ValueError("Invalid data URL: expected a comma after the MIME type.")
return input_data.split(",", 1)[1]
return input_data
def decode_base64_payload(payload: str) -> bytes:
try:
return base64.b64decode(payload, validate=True)
except Exception as e:
raise ValueError(
f"Invalid Base64 input: {e}. "
"Ensure the string is complete and correctly padded."
) from e
def infer_file_type_from_bytes(data: bytes) -> Optional[str]:
import puremagic
mime = puremagic.from_string(data, mime=True)View on GitHub (pinned to 2661c7c0ef)
Solutions
- Send a well-formed data URL: `data:image/png;base64,<payload>` with the comma present.
- Or send the bare base64 string without the `data:` prefix — extract_base64_payload passes it through unchanged.
- Build data URLs with a helper (f"data:{mime};base64,{b64}") instead of string concatenation.
Example fix
// before
await tool.ocr("data:image/png;base64")
// after
b64 = base64.b64encode(png_bytes).decode()
await tool.ocr(f"data:image/png;base64,{b64}") Defensive patterns
Strategy: validation
Validate before calling
def data_url_well_formed(s: str) -> bool:
if not s.startswith("data:"):
return True # bare base64 passes through
return "," in s Type guard
def is_parseable_data_url(value: object) -> bool:
return isinstance(value, str) and (not value.startswith("data:") or "," in value) Try / catch
try:
payload = extract_base64_payload(user_input)
except ValueError as e:
if "comma after the MIME type" in str(e):
raise ValueError(
"expected 'data:<mime>;base64,<payload>' or a bare base64 string"
) from e
raise Prevention
- Build data URLs with f-strings that visibly include the comma: f"data:{mime};base64,{b64}".
- Validate client-side that any 'data:' string contains ',' before sending to the MCP tool.
- Prefer sending bare base64 without the data: prefix when the API accepts it.
When it happens
Trigger: MCP client sends `data:image/png;base64` (payload omitted), `data:image/png` (no parameters and no payload), or a truncated paste where the comma was cut off.
Common situations: Template string built by concatenation that forgets the ',' separator; client-side truncation of long base64 strings at a fixed buffer size; LLM tool callers emitting malformed data URLs.
Related errors
- Invalid Base64 input: {e}. Ensure the string is complete and
- Unknown provider: {provider}
- Unsupported model: {normalized!r}. Supported models: {suppor
- The input data is inconsistent with expectations.
- Unsupported model: {model!r}
AI-assisted analysis of PaddlePaddle/PaddleOCR@2661c7c0ef (2026-08-14).
Data as JSON: /api/errors/0a504668a839645c.
Report an issue: GitHub.