{"record":{"id":"605416ee216a9bc2","repo":"ATH-MaaS/Pixelle-Video","slug":"url-task-id-task-id","errorCode":null,"errorMessage":"可灵任务成功但视频 URL 为空 (task_id={task_id})","messagePattern":"可灵任务成功但视频 URL 为空 \\(task_id=(.+?)\\)","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"pixelle_video/services/api_services/video_kling.py","lineNumber":399,"sourceCode":"            model_name=model,\n            mode=mode,\n            duration=str(duration),\n            cfg_scale=cfg_scale,\n            sound=sound,\n            aspect_ratio=aspect_ratio,\n        )\n\n        # 2. 轮询等待\n        result = self._poll_until_done(task_id, endpoint=endpoint)\n\n        # 3. 提取视频 URL\n        videos = result.get(\"task_result\", {}).get(\"videos\", [])\n        if not videos:\n            raise RuntimeError(f\"可灵任务成功但未返回视频数据 (task_id={task_id})\")\n\n        video_url = videos[0].get(\"url\", \"\")\n        if not video_url:\n            raise RuntimeError(f\"可灵任务成功但视频 URL 为空 (task_id={task_id})\")\n\n        # 4. 下载到本地\n        self._download_video(video_url, save_path)\n\n        return video_url\n\n\nif __name__ == \"__main__\":\n    import sys\n    sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))\n    from config import Config\n\n    logging.basicConfig(level=logging.INFO, format=\"%(asctime)s %(levelname)s %(message)s\")\n\n    # ── 测试参数（按需修改） ──\n    IMAGE_PATH = \"code/result/image/test_avail/test_input.png\"\n    OUTPUT_PATH = \"code/result/video/test_avail/kling_test_output.mp4\"\n    PROMPT = \"\"","sourceCodeStart":381,"sourceCodeEnd":417,"githubUrl":"https://github.com/ATH-MaaS/Pixelle-Video/blob/848b054e4fae40dabc62ec58e960b573e83793ac/pixelle_video/services/api_services/video_kling.py#L381-L417","documentation":"The videos array exists in the succeeded task's task_result, but the first entry's 'url' field is empty or missing. Since there is no downloadable URL, generate_video raises RuntimeError rather than attempting a download.","triggerScenarios":"videos[0].get('url', '') is falsy after a 'succeed' status (video_kling.py:397-399) — the video entry uses a different URL key (e.g. 'resource_url'/'download_url') after an API schema change, or Kling returned a placeholder entry with no URL for a partially failed generation.","commonSituations":"Kling renaming the URL field in a newer API version, responses where the first video entry contains only id/duration metadata and the URL lives elsewhere, or task marked succeed but asset generation actually incomplete on the storage side.","solutions":["Log videos[0] and inspect available keys; update extraction to the current URL field name if Kling renamed it.","Try alternate keys defensively: url = v.get('url') or v.get('resource_url') or v.get('download_url').","Resubmit the task — if it reproduces with an empty URL every time, treat it as a schema/account issue and contact Kling support with the task_id.","Ensure no client-side transformation (proxy, SDK model class) strips the url field before extraction."],"exampleFix":"# before\nvideo_url = videos[0].get(\"url\", \"\")\n# after\nfirst = videos[0] if videos else {}\nvideo_url = first.get(\"url\") or first.get(\"resource_url\") or first.get(\"download_url\") or \"\"","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"def extract_video_url(result: dict) -> str:\n    videos = (result.get(\"task_result\") or {}).get(\"videos\") or []\n    if not videos:\n        return \"\"\n    first = videos[0]\n    return first.get(\"url\") or first.get(\"resource_url\") or first.get(\"download_url\") or \"\"","tryCatchPattern":"try:\n    url = client.generate_video(...)\nexcept RuntimeError as e:\n    if \"视频 URL 为空\" in str(e):\n        logger.error(f\"视频条目缺少 url 字段，疑似字段更名: {e}\")\n        # 检查 videos[0] 的实际键名并更新提取逻辑","preventionTips":["Extract the URL defensively across known key variants (url/resource_url/download_url)","Log the first video entry when extraction fails to discover the current key name","Track Kling API changelogs for response field renames","Treat persistently empty URLs as an account/backend issue and report with task_id"],"tags":["kling","empty-url","schema-change","api-response"],"backgroundTag":"task-completed-no-result-url","analyzedSha":"848b054e4fae40dabc62ec58e960b573e83793ac","analyzedAt":"2026-08-30T03:24:41.468Z","schemaVersion":2},"datasetVersion":"2026-08-30T08:17:16.595Z"}