fix(jimeng_video_gen): 解决视频下载失败和状态检查问题
- 添加视频下载重试机制,最多重试3次 - 增加下载超时设置为60秒 - 添加下载失败时的错误提示信息 - 修复任务状态检查逻辑,避免空响应导致的错误 - 改进错误处理流程,提高脚本稳定性
This commit is contained in:
parent
9408daeeff
commit
2c96bf7b7f
@ -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':
|
if resp_code == 10000 and resp_data.get('status') == 'done':
|
||||||
video_url = resp_data.get('video_url')
|
video_url = resp_data.get('video_url')
|
||||||
if video_url:
|
if video_url:
|
||||||
# 下载视频
|
# 下载视频(带重试)
|
||||||
print(f"[即梦视频] 生成完成,正在下载...")
|
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)
|
_ensure_dir(output_path)
|
||||||
with open(output_path, 'wb') as f:
|
with open(output_path, 'wb') as f:
|
||||||
f.write(video_data)
|
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]}")
|
print(f"[即梦视频] 任务完成但未找到视频URL: {json.dumps(result, ensure_ascii=False)[:300]}")
|
||||||
return None
|
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]}")
|
print(f"[即梦视频] 任务失败: {json.dumps(result, ensure_ascii=False)[:300]}")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user