ATH-MaaS/Pixelle-Video · error · ValueError
无法解析 base64 图片: {e}
Error message
无法解析 base64 图片: {e} What it means
_to_dashscope_file_url wraps any exception raised while decoding/writing a base64 image data URL into ValueError('无法解析 base64 图片: {e}'). The decode, mime/header parsing, or temp-file write failed.
Source
Thrown at pixelle_video/services/api_services/vlm_client.py:89
if path.startswith("data:"):
if not allow_data_url:
raise ValueError("DashScope video input does not support data URLs in this adapter.")
import base64 as b64
import tempfile
try:
header, b64_data = path.split(",", 1)
mime_type = header.split(";")[0].replace("data:", "")
image_data = b64.b64decode(b64_data)
suffix = f".{mime_type.split('/')[-1]}" if "/" in mime_type else ".png"
with tempfile.NamedTemporaryFile(suffix=suffix, delete=False) as tmp:
tmp.write(image_data)
temp_path = tmp.name
return f"file://{os.path.abspath(temp_path)}"
except Exception as e:
print(f"Error processing base64 image: {e}")
raise ValueError(f"无法解析 base64 图片: {e}")
if path.startswith("http") or path.startswith("file://"):
return path
return f"file://{os.path.abspath(path)}"
View on GitHub (pinned to 848b054e4f)
Solutions
- Validate the data URL format before calling: starts with 'data:image/', contains ';base64,', and the payload is valid base64 (try base64.b64decode(payload, validate=True))
- Strip whitespace/newlines from the base64 payload and re-encode URL-safe base64 to standard
- Check the error suffix ({e}) in the message — it names the underlying cause (binascii.Error, OSError, etc.)
- Bypass the data URL path: save the image to a file and pass the local path instead
Example fix
// before
images=[f"data:image/png;base64,{raw_b64}"] # raw_b64 may contain newlines
// after
import base64
clean = raw_b64.replace("\n", "").replace("\r", "").replace("-", "+").replace("_", "/")
base64.b64decode(clean, validate=True) # fail fast with a clear error
images=[f"data:image/png;base64,{clean}"] Defensive patterns
Strategy: validation
Validate before calling
import base64, re
def validate_image_data_url(p: str) -> str:
m = re.fullmatch(r"data:image/(png|jpe?g);base64,([A-Za-z0-9+/=\s]+)", p)
if not m:
raise ValueError("not a valid image data URL")
payload = "".join(m.group(2).split())
base64.b64decode(payload, validate=True)
return p Type guard
def is_valid_base64(s: str) -> bool:
import base64
try:
base64.b64decode("".join(s.split()), validate=True)
return True
except Exception:
return False Try / catch
try:
answer = vlm.query(prompt=p, image_paths=[img], model="qwen-vl-max")
except ValueError as e:
if "base64" in str(e):
logging.error(f"Malformed base64 image input: {e}") # fix encoding upstream or write to a file
else:
raise Prevention
- Strip newlines/whitespace and normalize URL-safe base64 before building data URLs
- Verify the data URL has a proper 'data:image/...;base64,' header
- Prefer passing local file paths over inline base64 when possible
When it happens
Trigger: Passing an image_paths entry like 'data:image/png;base64,...' whose base64 payload is malformed, header lacks a mime type/extension the parser understands, or whose decoded bytes cannot be written to the temp file (disk full, permissions).
Common situations: Truncated base64 string (cut off during serialization); whitespace/newlines inside base64; data URL missing the 'data:...;base64,' prefix; URL-safe base64 (-, _) from another service without re-encoding; no space in /tmp.
Related errors
- DashScope video input does not support data URLs in this ada
- DashScope reference-to-video models require at least one ref
- DashScope video edit models require video input and may use
- DashScope legacy video models require image_path.
- Invalid DashScope media combination: {'+'.join(sorted(media_
AI-assisted analysis of ATH-MaaS/Pixelle-Video@848b054e4f (2026-08-30).
Data as JSON: /api/errors/8ba6d388237a48c6.
Report an issue: GitHub.