{"record":{"id":"3f10ef4bb86a5e6e","repo":"sgl-project/sglang","slug":"unrecognized-image-input-support-local-path-http","errorCode":null,"errorMessage":"Unrecognized image input, support local path, http url, base64 and PIL.Image, got {image}","messagePattern":"Unrecognized image input, support local path, http url, base64 and PIL\\.Image, got (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/srt/multimodal/processors/mimo_v2.py","lineNumber":1468,"sourceCode":"            image_obj = image\n        elif isinstance(image, str):\n            if image.startswith(\"http://\") or image.startswith(\"https://\"):\n                with BytesIO(download_remote_media(image, timeout=3)) as bio:\n                    image_obj = copy.deepcopy(Image.open(bio))\n            elif image.startswith(\"file://\"):\n                image_obj = Image.open(image[7:])\n            elif image.startswith(\"data:image\"):\n                if \"base64,\" in image:\n                    _, base64_data = image.split(\"base64,\", 1)\n                    data = base64.b64decode(base64_data)\n                    with BytesIO(data) as bio:\n                        image_obj = copy.deepcopy(Image.open(bio))\n            else:\n                image_obj = Image.open(image)\n        else:\n            image_obj = Image.open(BytesIO(image))\n        if image_obj is None:\n            raise ValueError(\n                f\"Unrecognized image input, support local path, http url, base64 and PIL.Image, got {image}\"\n            )\n        image = cls.to_rgb(image_obj)\n        return image\n\n\nclass MiMoV2Processor(BaseMultimodalProcessor):\n    models = [MiMoV2ForCausalLM]\n\n    @staticmethod\n    def _normalize_config_dict(config, name: str) -> dict:\n        if config is None:\n            return {}\n        if isinstance(config, dict):\n            return config\n        if hasattr(config, \"to_dict\"):\n            return config.to_dict()\n        raise ValueError(f\"{name} must be a dict-like config, got {type(config)}\")","sourceCodeStart":1450,"sourceCodeEnd":1486,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/srt/multimodal/processors/mimo_v2.py#L1450-L1486","documentation":"Raised by fetch_image when the image argument can't be opened through any supported route (local path via Image.open, bytes via BytesIO, base64, or PIL.Image) and image_obj ends up None. The message echoes the offending input value.","triggerScenarios":"Calling process_image/fetch_image with a value that falls through all branches — e.g. a malformed base64 string that decodes to nothing openable, a file-like object, an int/None, or a corrupt byte payload that Image.open silently fails on in this flow.","commonSituations":"Bad base64 (missing padding, data-URI prefix not stripped); corrupt image bytes; clients sending file handles instead of bytes; None values slipping through request parsing.","solutions":["Send a plain base64 string (strip 'data:image/...;base64,' prefixes) or raw image bytes","Verify the image opens locally: PIL.Image.open(BytesIO(b64decode(s))).verify()","For local files, pass the filesystem path string"],"exampleFix":"# before\nimg_b64 = 'data:image/png;base64,iVBOR...'   # prefix not stripped\n# after\nimport base64\nimg_b64 = 'iVBOR...'  # or base64.b64encode(open('x.png','rb').read()).decode()","handlingStrategy":"validation","validationCode":"from io import BytesIO\nfrom PIL import Image\nimport base64, re\ndef is_loadable_image(s):\n    try:\n        raw = base64.b64decode(re.sub(r'^data:[^;]+;base64,', '', s))\n        Image.open(BytesIO(raw)).verify()\n        return True\n    except Exception:\n        return False","typeGuard":"def is_recognized_image_input(x) -> bool:\n    return (isinstance(x, (str, bytes)) or isinstance(x, Image.Image)) and \\\n           (not isinstance(x, str) or not x.startswith('data:'))","tryCatchPattern":"try:\n    im = MiMoProcessor.fetch_image(image)\nexcept ValueError as e:\n    if 'Unrecognized image input' in str(e):\n        return error_response(400, 'send base64 without data-URI prefix, raw bytes, a path, or a URL')\n    raise","preventionTips":["Strip data-URI prefixes before sending base64","Verify bytes decode with PIL before upload","Never send None or file handles as image payloads"],"tags":["image","loading","base64","input-validation"],"backgroundTag":"unrecognized-image-input","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}