ATH-MaaS/Pixelle-Video · error · RuntimeError
可灵任务成功但视频 URL 为空 (task_id={task_id})
Error message
可灵任务成功但视频 URL 为空 (task_id={task_id}) What it means
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.
Source
Thrown at pixelle_video/services/api_services/video_kling.py:399
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")
# ── 测试参数(按需修改) ──
IMAGE_PATH = "code/result/image/test_avail/test_input.png"
OUTPUT_PATH = "code/result/video/test_avail/kling_test_output.mp4"
PROMPT = ""View on GitHub (pinned to 848b054e4f)
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.
Example fix
# before
video_url = videos[0].get("url", "")
# after
first = videos[0] if videos else {}
video_url = first.get("url") or first.get("resource_url") or first.get("download_url") or "" Defensive patterns
Strategy: type-guard
Type guard
def extract_video_url(result: dict) -> str:
videos = (result.get("task_result") or {}).get("videos") or []
if not videos:
return ""
first = videos[0]
return first.get("url") or first.get("resource_url") or first.get("download_url") or "" Try / catch
try:
url = client.generate_video(...)
except RuntimeError as e:
if "视频 URL 为空" in str(e):
logger.error(f"视频条目缺少 url 字段,疑似字段更名: {e}")
# 检查 videos[0] 的实际键名并更新提取逻辑 Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- 可灵任务成功但未返回视频数据 (task_id={task_id})
- Image edit failed: {response.code}, {response.message}, stat
- 万象视频任务完成后仍未返回 video_url: code={rsp.code}, message={rsp.messa
- 输入图片不存在: {image_path}
- 可灵 API 错误: code={data.get('code')}, message={data.get('messa
AI-assisted analysis of ATH-MaaS/Pixelle-Video@848b054e4f (2026-08-30).
Data as JSON: /api/errors/605416ee216a9bc2.
Report an issue: GitHub.