From 2c96bf7b7f11394c955f2a62ceeab4080887af99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=93=E6=96=87=E5=85=B5?= <441889070@qq.com> Date: Sat, 14 Mar 2026 10:26:34 +0800 Subject: [PATCH] =?UTF-8?q?fix(jimeng=5Fvideo=5Fgen):=20=E8=A7=A3=E5=86=B3?= =?UTF-8?q?=E8=A7=86=E9=A2=91=E4=B8=8B=E8=BD=BD=E5=A4=B1=E8=B4=A5=E5=92=8C?= =?UTF-8?q?=E7=8A=B6=E6=80=81=E6=A3=80=E6=9F=A5=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 添加视频下载重试机制,最多重试3次 - 增加下载超时设置为60秒 - 添加下载失败时的错误提示信息 - 修复任务状态检查逻辑,避免空响应导致的错误 - 改进错误处理流程,提高脚本稳定性 --- scripts/jimeng_video_gen.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/scripts/jimeng_video_gen.py b/scripts/jimeng_video_gen.py index 0fd865e..d6820ca 100644 --- a/scripts/jimeng_video_gen.py +++ b/scripts/jimeng_video_gen.py @@ -89,9 +89,19 @@ def _submit_and_poll(req_key, body, output_path, max_wait=180, poll_interval=10) if resp_code == 10000 and resp_data.get('status') == 'done': video_url = resp_data.get('video_url') if video_url: - # 下载视频 + # 下载视频(带重试) print(f"[即梦视频] 生成完成,正在下载...") - video_data = requests.get(video_url).content + video_data = None + for attempt in range(3): + try: + video_data = requests.get(video_url, timeout=60, verify=False).content + break + except Exception as e: + print(f"[即梦视频] 下载重试 ({attempt+1}/3): {e}") + import time as _t; _t.sleep(3) + if video_data is None: + print(f"[即梦视频] 下载失败,视频URL: {video_url[:200]}") + return None _ensure_dir(output_path) with open(output_path, 'wb') as f: f.write(video_data) @@ -101,7 +111,7 @@ def _submit_and_poll(req_key, body, output_path, max_wait=180, poll_interval=10) print(f"[即梦视频] 任务完成但未找到视频URL: {json.dumps(result, ensure_ascii=False)[:300]}") return None - if resp_code != 10000 and resp_data.get('status') not in (None, 'running', 'pending'): + if resp_code != 10000 and (resp_data is None or resp_data.get('status') not in (None, 'running', 'pending')): print(f"[即梦视频] 任务失败: {json.dumps(result, ensure_ascii=False)[:300]}") return None