ATH-MaaS/Pixelle-Video · error · RuntimeError

可灵任务成功但未返回视频数据 (task_id={task_id})

Error message

可灵任务成功但未返回视频数据 (task_id={task_id})

What it means

The Kling task reported 'succeed', but the response's task_result contains no videos array. generate_video treats a success status without video entries as a contract violation and raises RuntimeError, since there is nothing to download.

Source

Thrown at pixelle_video/services/api_services/video_kling.py:395

        task_id = self._submit_task(
            image_path=image_path,
            prompt=prompt,
            negative_prompt=negative_prompt,
            model_name=model,
            mode=mode,
            duration=str(duration),
            cfg_scale=cfg_scale,
            sound=sound,
            aspect_ratio=aspect_ratio,
        )

        # 2. 轮询等待
        result = self._poll_until_done(task_id, endpoint=endpoint)

        # 3. 提取视频 URL
        videos = result.get("task_result", {}).get("videos", [])
        if not videos:
            raise RuntimeError(f"可灵任务成功但未返回视频数据 (task_id={task_id})")

        video_url = videos[0].get("url", "")
        if not video_url:
            raise RuntimeError(f"可灵任务成功但视频 URL 为空 (task_id={task_id})")

        # 4. 下载到本地
        self._download_video(video_url, save_path)

        return video_url


if __name__ == "__main__":
    import sys
    sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
    from config import Config

    logging.basicConfig(level=logging.INFO, format="%(asctime)s %(levelname)s %(message)s")

View on GitHub (pinned to 848b054e4f)

Solutions

  1. Log the full `result` dict to see the actual response shape; if Kling moved the videos field, update the extraction path accordingly.
  2. Pin/upgrade to the Kling API version whose schema matches the extraction code, and re-test with a simple image2video request.
  3. Disable any intermediary proxy/response rewriting and confirm the raw JSON contains task_result.videos.
  4. Retry generation once — if it reproduces on every success, it is a schema issue, not a transient one.

Example fix

# before
videos = result.get("task_result", {}).get("videos", [])
# after
result_data = result.get("data", result)  # 兼容不同包装层级
videos = (result_data.get("task_result") or {}).get("videos") or []
Defensive patterns

Strategy: type-guard

Type guard

def has_videos(result: dict) -> bool:
    videos = (result.get("task_result") or {}).get("videos") or []
    return len(videos) > 0

Try / catch

try:
    url = client.generate_video(...)
except RuntimeError as e:
    if "未返回视频数据" in str(e):
        logger.error(f"成功但无视频载荷,疑似 schema 变更: {e}")
        # 上报并检查 API 版本,必要时升级/降级客户端

Prevention

When it happens

Trigger: After _poll_until_done returns, result.get('task_result', {}).get('videos', []) is empty (video_kling.py:394-395) — Kling returned success but omitted the video payload, usually due to an undocumented API response-shape change, partial success, or SDK/proxy mangling the body.

Common situations: Kling API version update altering the response schema (e.g. nesting videos differently), a proxy/CDN truncating the JSON, or tasks that succeed with zero outputs in edge cases (degenerate inputs).

Related errors


AI-assisted analysis of ATH-MaaS/Pixelle-Video@848b054e4f (2026-08-30). Data as JSON: /api/errors/53bb9e706bfb4fee. Report an issue: GitHub.