{"record":{"id":"d91cb72b9be91b11","repo":"xtekky/gpt4free","slug":"invalid-or-disallowed-media-url","errorCode":null,"errorMessage":"Invalid or disallowed media URL","messagePattern":"Invalid or disallowed media URL","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"g4f/image/__init__.py","lineNumber":456,"sourceCode":"def to_bytes(image: ImageType) -> bytes:\n    \"\"\"\n    Converts the given image to bytes.\n\n    Args:\n        image (ImageType): The image to convert.\n\n    Returns:\n        bytes: The image as bytes.\n    \"\"\"\n    if isinstance(image, bytes):\n        return image\n    elif isinstance(image, str):\n        if image.startswith(\"data:\"):\n            is_data_uri_an_image(image)\n            return extract_data_uri(image)\n        elif image.startswith(\"http://\") or image.startswith(\"https://\"):\n            if not is_safe_url(image):\n                raise ValueError(\"Invalid or disallowed media URL\")\n            path: str = urlparse(image).path\n            if path.startswith(\"/files/\"):\n                path = get_bucket_dir(*path.split(\"/\")[2:])\n                if os.path.exists(path):\n                    return Path(path).read_bytes()\n                else:\n                    raise FileNotFoundError(f\"File not found: {path}\")\n            else:\n                if not is_safe_url(image):\n                    raise ValueError(\"Invalid or unsafe image url\")\n                resp = requests.get(\n                    image,\n                    headers={\n                        \"User-Agent\": \"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0 Safari/537.36 Edg/137.0.0.0\",\n                    },\n                )\n                if resp.ok and is_accepted_format(resp.content):\n                    return resp.content","sourceCodeStart":438,"sourceCodeEnd":474,"githubUrl":"https://github.com/xtekky/gpt4free/blob/973504e1770928ed5fb82f43da528f441ad9ddc3/g4f/image/__init__.py#L438-L474","documentation":"Error \"Invalid or disallowed media URL\" thrown in xtekky/gpt4free.","triggerScenarios":"Thrown at g4f/image/__init__.py:456 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Use an http(s) URL pointing directly to an image.","Remove disallowed schemes or private addresses from the URL."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"973504e1770928ed5fb82f43da528f441ad9ddc3","analyzedAt":"2026-08-14T23:45:32.408Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}