xtekky/gpt4free · error · ValueError

Invalid data URI image. {data_uri[:10]}...

Error message

Invalid data URI image. {data_uri[:10]}...

What it means

Error "Invalid data URI image. {data_uri[:10]}..." thrown in xtekky/gpt4free.

Source

Thrown at g4f/image/__init__.py:238

        return False
    return True


def is_data_uri_an_image(data_uri: str) -> bool:
    """
    Checks if the given data URI represents an image.

    Args:
        data_uri (str): The data URI to check.

    Raises:
        ValueError: If the data URI is invalid or the image format is not allowed.
    """
    if data_uri.startswith("https:") or data_uri.startswith("http:"):
        return True
    # Check if the data URI starts with 'data:image' and contains an image format (e.g., jpeg, png, gif)
    if not re.match(r"data:image/(\w+);base64,", data_uri):
        raise ValueError(f"Invalid data URI image. {data_uri[:10]}...")
    # Extract the image format from the data URI
    image_format = re.match(r"data:image/(\w+);base64,", data_uri).group(1).lower()
    # Check if the image format is one of the allowed formats (jpg, jpeg, png, gif)
    if image_format not in EXTENSIONS_MAP and image_format != "svg+xml":
        raise ValueError("Invalid image format (from mime file type).")
    return True


def is_accepted_format(binary_data: bytes) -> str:
    """
    Checks if the given binary data represents an image with an accepted format.

    Args:
        binary_data (bytes): The binary data to check.

    Raises:
        ValueError: If the image format is not allowed.
    """

View on GitHub (pinned to 973504e177)

Solutions

  1. Provide a valid data URI starting with data:image/...;base64,....

When it happens

Trigger: Thrown at g4f/image/__init__.py:238 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of xtekky/gpt4free@973504e177 (2026-08-14). Data as JSON: /api/errors/43bb7601c48c9217. Report an issue: GitHub.