{"record":{"id":"27bb4a7e28c5f6f2","repo":"agentscope-ai/agentscope","slug":"unsupported-video-source-type-type-source","errorCode":null,"errorMessage":"Unsupported video source type: {type(source)}","messagePattern":"Unsupported video source type: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/agentscope/formatter/_dashscope_formatter.py","lineNumber":164,"sourceCode":"        \"\"\"Convert a video source to DashScope's ``video_url`` format\n        (OpenAI-compatible extension).\n\n        Local ``file://`` URLs are read from disk and converted to base64\n        data URIs. Remote URLs are passed through unchanged.\n        \"\"\"\n        if isinstance(source, Base64Source):\n            url = f\"data:{source.media_type};base64,{source.data}\"\n        elif isinstance(source, URLSource):\n            url_str = str(source.url)\n            if url_str.startswith(\"file://\"):\n                local_path = url_str.removeprefix(\"file://\")\n                with open(local_path, \"rb\") as f:\n                    encoded = base64.b64encode(f.read()).decode(\"utf-8\")\n                url = f\"data:{source.media_type};base64,{encoded}\"\n            else:\n                url = url_str\n        else:\n            raise ValueError(f\"Unsupported video source type: {type(source)}\")\n\n        return {\n            \"type\": \"video_url\",\n            \"video_url\": {\"url\": url},\n        }\n\n    @staticmethod\n    def _format_audio_source(\n        source: URLSource | Base64Source,\n    ) -> dict[str, Any]:\n        \"\"\"Convert an audio source to DashScope ``input_audio`` format.\n\n        DashScope's compatible API accepts URLs directly in the ``data``\n        field. Base64-encoded audio must be wrapped in a data URL. Local\n        files are read, base64-encoded, and wrapped in the same form.\n        \"\"\"\n        fmt = source.media_type.split(\"/\")[-1]\n        if fmt == \"mpeg\":","sourceCodeStart":146,"sourceCodeEnd":182,"githubUrl":"https://github.com/agentscope-ai/agentscope/blob/e90f1c7592896cc95f6e5ee506194f533378247d/src/agentscope/formatter/_dashscope_formatter.py#L146-L182","documentation":"Video counterpart of the image guard: while formatting a video DataBlock for DashScope, the source is neither a supported inline/local type (converted to a data: URL) nor a URL source, so formatting aborts with ValueError.","triggerScenarios":"Video DataBlock with source=None, a plain dict, or a foreign/custom source class passed to a DashScope model; _format_video_source reaches its final else.","commonSituations":"Large video files where source loading failed silently and left None; mixed-version imports; converting from OpenAI video formats that use dicts.","solutions":["Re-encode path as Base64Source/local file source or reference the hosted file with URLSource","Check that video loading actually succeeded (source is not None) before building the message","Keep a single agentscope version in the environment"],"exampleFix":"# before\nblock = DataBlock(source=None, media_type=\"video/mp4\")\n\n# after\nfrom agentscope.message import DataBlock, URLSource\nblock = DataBlock(source=URLSource(url=\"https://cdn/x.mp4\", media_type=\"video/mp4\"))","handlingStrategy":"type-guard","validationCode":"from agentscope.message import Base64Source, URLSource\nfor block in msg_video_blocks:\n    if not isinstance(getattr(block, \"source\", None), (Base64Source, URLSource)):\n        raise TypeError(\"video block source unsupported\")","typeGuard":"from agentscope.message import DataBlock, Base64Source, URLSource\n\ndef video_block_ok(block: DataBlock) -> bool:\n    return isinstance(getattr(block, \"source\", None), (Base64Source, URLSource))","tryCatchPattern":"try:\n    resp = await model(msg)\nexcept ValueError as e:\n    if \"Unsupported video source type\" in str(e):\n        msg = normalize_video_blocks(msg)\n        resp = await model(msg)\n    else:\n        raise","preventionTips":["Check video download/load succeeded (source set) before building messages","Use URLSource for large videos instead of inline base64","Normalize all media blocks through one helper before sending"],"tags":["dashscope","qwen","formatter","video","source-type"],"backgroundTag":"unsupported-source-type","analyzedSha":"e90f1c7592896cc95f6e5ee506194f533378247d","analyzedAt":"2026-08-28T18:24:12.087Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}