microsoft/autogen · error · ValueError
Invalid URI format. It should be a base64 encoded image URI.
Error message
Invalid URI format. It should be a base64 encoded image URI.
What it means
Error "Invalid URI format. It should be a base64 encoded image URI." thrown in microsoft/autogen.
Source
Thrown at python/packages/autogen-core/src/autogen_core/_image.py:52
content = await response.read()
return Image.from_pil(PILImage.open(content))
image = asyncio.run(from_url("https://example.com/image"))
"""
def __init__(self, image: PILImage.Image):
self.image: PILImage.Image = image.convert("RGB")
@classmethod
def from_pil(cls, pil_image: PILImage.Image) -> Image:
return cls(pil_image)
@classmethod
def from_uri(cls, uri: str) -> Image:
if not re.match(r"data:image/(?:png|jpeg);base64,", uri):
raise ValueError("Invalid URI format. It should be a base64 encoded image URI.")
# A URI. Remove the prefix and decode the base64 string.
base64_data = re.sub(r"data:image/(?:png|jpeg);base64,", "", uri)
return cls.from_base64(base64_data)
@classmethod
def from_base64(cls, base64_str: str) -> Image:
return cls(PILImage.open(BytesIO(base64.b64decode(base64_str))))
def to_base64(self) -> str:
buffered = BytesIO()
self.image.save(buffered, format="PNG")
content = buffered.getvalue()
return base64.b64encode(content).decode("utf-8")
@classmethod
def from_file(cls, file_path: Path) -> Image:
return cls(PILImage.open(file_path))View on GitHub (pinned to 027ecf0a37)
Solutions
- Use data:<mediatype>;base64,<data> format
Example fix
Image.from_uri('data:image/png;base64,...') When it happens
Trigger: Thrown at python/packages/autogen-core/src/autogen_core/_image.py:52 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of microsoft/autogen@027ecf0a37 (2026-08-15).
Data as JSON: /api/errors/42e3a26b2d078222.
Report an issue: GitHub.