ATH-MaaS/Pixelle-Video · error · RuntimeError

视频下载失败: HTTP {resp.status_code}

Error message

视频下载失败: HTTP {resp.status_code}

What it means

After DashScope returns a video URL, generate_video downloads it with requests.get (wrapped in network retry). If the final HTTP response status is not 200 — even after up to 5 retry attempts with 3s base delay — the client raises RuntimeError '视频下载失败: HTTP <status>'.

Source

Thrown at pixelle_video/services/api_services/video_dashscope.py:415

        logger.info(f"DashscopeVideoClient: 视频生成成功: {video_url}")

        # 确保输出目录存在
        os.makedirs(os.path.dirname(save_path), exist_ok=True)

        # 下载视频
        resp = self._with_network_retry(
            "download video",
            lambda: requests.get(
                video_url,
                stream=True,
                timeout=120,
                proxies={"http": self.local_proxy, "https": self.local_proxy} if self.local_proxy else None,
            ),
            max_attempts=5,
            base_delay=3.0,
        )
        if resp.status_code != 200:
            raise RuntimeError(f"视频下载失败: HTTP {resp.status_code}")

        with open(save_path, 'wb') as f:
            for chunk in resp.iter_content(chunk_size=8192):
                if chunk:
                    f.write(chunk)

        logger.info(f"DashscopeVideoClient: 视频已保存: {save_path}")
        return video_url

    def _is_video_edit_model(self, model: str) -> bool:
        """Return True for DashScope video-edit model IDs."""
        model_lower = model.lower()
        return "videoedit" in model_lower or "video-edit" in model_lower

    def _is_reference_to_video_model(self, model: str) -> bool:
        """Return True for DashScope reference-to-video model IDs."""
        return "r2v" in model.lower()

View on GitHub (pinned to 848b054e4f)

Solutions

  1. Download the video promptly after generation; signed OSS URLs expire, so re-run generation if the URL is old.
  2. Check the status code: 403/404 means the URL is expired or invalid — regenerate; 5xx means transient — retry later.
  3. Verify self.local_proxy is correct or None; a bad proxy often yields 403/407 from the CDN.
  4. Increase max_attempts/base_delay in _with_network_retry for the download call if CDN flakiness is common in your region.

Example fix

# before
if resp.status_code != 200:
    raise RuntimeError(f"视频下载失败: HTTP {resp.status_code}")
# after
if resp.status_code != 200:
    if resp.status_code in (403, 404):
        raise RuntimeError(
            f"视频下载失败: HTTP {resp.status_code} (URL 可能已过期,请重新生成)"
        )
    raise RuntimeError(f"视频下载失败: HTTP {resp.status_code}")
Defensive patterns

Strategy: retry

Validate before calling

import requests
def url_alive(video_url: str, proxy: str | None = None) -> bool:
    try:
        r = requests.head(video_url, timeout=10, allow_redirects=True,
                          proxies={"http": proxy, "https": proxy} if proxy else None)
        return r.status_code == 200
    except requests.RequestException:
        return False

Try / catch

try:
    url = client.generate_video(...)
except RuntimeError as e:
    if "视频下载失败" in str(e):
        status = int(str(e).rsplit("HTTP ", 1)[-1])
        if status in (403, 404):
            url = client.generate_video(...)  # URL 过期/失效,重新生成
        else:
            time.sleep(5); url = client.generate_video(...)  # 5xx 稍后重试

Prevention

When it happens

Trigger: requests.get(video_url, stream=True, timeout=120) returns a non-200 status after _with_network_retry exhausts max_attempts=5; typically 403 (expired/protected CDN URL), 404 (deleted object), or 5xx from the Aliyun OSS/CDN host (video_dashscope.py:403-415).

Common situations: Waiting too long between generation and download so the signed URL expires (DashScope video URLs are time-limited), corporate proxy misconfiguring self.local_proxy, CDN transient outage during retries, or the generated object being cleaned up server-side.

Related errors


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