{"record":{"id":"8ba6d388237a48c6","repo":"ATH-MaaS/Pixelle-Video","slug":"base64-e","errorCode":null,"errorMessage":"无法解析 base64 图片: {e}","messagePattern":"无法解析 base64 图片: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"pixelle_video/services/api_services/vlm_client.py","lineNumber":89,"sourceCode":"        if path.startswith(\"data:\"):\n            if not allow_data_url:\n                raise ValueError(\"DashScope video input does not support data URLs in this adapter.\")\n\n            import base64 as b64\n            import tempfile\n\n            try:\n                header, b64_data = path.split(\",\", 1)\n                mime_type = header.split(\";\")[0].replace(\"data:\", \"\")\n                image_data = b64.b64decode(b64_data)\n                suffix = f\".{mime_type.split('/')[-1]}\" if \"/\" in mime_type else \".png\"\n                with tempfile.NamedTemporaryFile(suffix=suffix, delete=False) as tmp:\n                    tmp.write(image_data)\n                    temp_path = tmp.name\n                return f\"file://{os.path.abspath(temp_path)}\"\n            except Exception as e:\n                print(f\"Error processing base64 image: {e}\")\n                raise ValueError(f\"无法解析 base64 图片: {e}\")\n\n        if path.startswith(\"http\") or path.startswith(\"file://\"):\n            return path\n\n        return f\"file://{os.path.abspath(path)}\"\n","sourceCodeStart":71,"sourceCodeEnd":95,"githubUrl":"https://github.com/ATH-MaaS/Pixelle-Video/blob/848b054e4fae40dabc62ec58e960b573e83793ac/pixelle_video/services/api_services/vlm_client.py#L71-L95","documentation":"_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.","triggerScenarios":"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).","commonSituations":"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.","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"],"exampleFix":"// before\nimages=[f\"data:image/png;base64,{raw_b64}\"]  # raw_b64 may contain newlines\n// after\nimport base64\nclean = raw_b64.replace(\"\\n\", \"\").replace(\"\\r\", \"\").replace(\"-\", \"+\").replace(\"_\", \"/\")\nbase64.b64decode(clean, validate=True)  # fail fast with a clear error\nimages=[f\"data:image/png;base64,{clean}\"]","handlingStrategy":"validation","validationCode":"import base64, re\ndef validate_image_data_url(p: str) -> str:\n    m = re.fullmatch(r\"data:image/(png|jpe?g);base64,([A-Za-z0-9+/=\\s]+)\", p)\n    if not m:\n        raise ValueError(\"not a valid image data URL\")\n    payload = \"\".join(m.group(2).split())\n    base64.b64decode(payload, validate=True)\n    return p","typeGuard":"def is_valid_base64(s: str) -> bool:\n    import base64\n    try:\n        base64.b64decode(\"\".join(s.split()), validate=True)\n        return True\n    except Exception:\n        return False","tryCatchPattern":"try:\n    answer = vlm.query(prompt=p, image_paths=[img], model=\"qwen-vl-max\")\nexcept ValueError as e:\n    if \"base64\" in str(e):\n        logging.error(f\"Malformed base64 image input: {e}\")  # fix encoding upstream or write to a file\n    else:\n        raise","preventionTips":["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"],"tags":["dashscope","vlm","base64","data-url","input-validation"],"backgroundTag":"invalid-base64","analyzedSha":"848b054e4fae40dabc62ec58e960b573e83793ac","analyzedAt":"2026-08-30T03:24:41.468Z","schemaVersion":2},"datasetVersion":"2026-08-30T08:17:16.595Z"}