#5658 AttributeError: 'NoneType' object has no attribute 'get'

123.110* Posted at: 11 hours ago

程序内部错误:'NoneType' object has no attribute 'get':Traceback (most recent call last):
File "videotrans\translator\_base.py", line 69, in run
File "videotrans\translator\_base.py", line 143, in _run_srt
File "tenacity\__init__.py", line 338, in wrapped_f
File "tenacity\__init__.py", line 477, in call
File "tenacity\__init__.py", line 378, in iter
File "tenacity\__init__.py", line 421, in exc_check
tenacity.RetryError: RetryError[]

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "videotrans\util\TestSrtTrans.py", line 19, in run
File "videotrans\translator\_runner.py", line 63, in run
File "videotrans\translator\_base.py", line 72, in run
File "tenacity\__init__.py", line 480, in call
File "videotrans\translator\_openaicompat.py", line 79, in _item_task
AttributeError: 'NoneType' object has no attribute 'get'


=
system:Windows-10-10.0.19043-SP0
version:v4.04
frozen:True
language:zh
root_dir:D:/pyvideotrans4040704

11 Replies

AttributeError: 'NoneType' object has no attribute 'get' 表明翻译渠道(如 DeepSeek、OpenAI 等)返回了空响应,通常是 API 请求失败后未返回正确数据。

可能原因与解决办法:

  1. API 密钥无效或余额不足

    • 检查翻译渠道的 API Key 是否正确、账户余额是否充足。
  2. 网络连接问题

    • 确认是否配置了正确的代理(主界面第 5 行“网络代理”框,格式如 http://127.0.0.1:7890)。
    • 如果使用国外 API(如 OpenAI、Gemini),中国大陆用户需要科学上网。
  3. API 地址错误或服务不可用

    • 若使用本地部署的兼容 API(如 localllm),请确认服务已启动且地址填写正确(不能是 0.0.0.0,应为 127.0.0.1)。
  4. 字幕行数过大或格式问题

    • 进入 菜单 → 高级选项 → 字幕翻译调整,适当降低“AI翻译渠道每批字幕行数”(如设为 20),并取消勾选“发送完整字幕”再试。

如果以上仍无法解决,请提供 logs/ 目录下最新日志文件的末尾 30 行。

请查阅相关文档:


Application started at 2026-07-06 07:51:41

1783295501:Loading resources...
1783295501:Loading main window...
1783295501:Initializing UI...
1783295501:SetupUI end...
1783295501:import recognition ...
1783295501:import tts ...
1783295501:import translate ...
1783295501:Get cache ...
1783295501:Set default value ...
1783295501:import voices list ...
1783295501:Set tts voice ...
[DEBUG] 上次缓存的角色:No,字幕嵌入类型:1,发音语言:en,目标语言:zh-cn,目标语言代码:None,模型:large-v3-turbo,TTS渠道[0]
1783295501:show main window ...
1783295501:Bind signal...
1783295501:set cursor...
1783295501:preload TTS win...
1783295502:preload STT win...
1783295502:preload translate srt win...
1783295502:end
[DEBUG] 平台: Windows。正在按优先级检测最佳的 'h264' 编码器: ['nvenc', 'qsv', 'amf']
[DEBUG] 正在测试编码器是否可用: h264_nvenc...
[DEBUG] 可用 Nvidia 显卡数: 1
[DEBUG] 找到 1 个 Nvidia GPUs, 耗时: 5s

[DEBUG] start 9 jobs
[DEBUG] 硬件编码器 'h264_nvenc' 可用。
[DEBUG] 已选择硬件编码器: h264_nvenc
[DEBUG] 最终确定使用的编码器: h264_nvenc
[DEBUG] 平台: Windows。正在按优先级检测最佳的 'hevc' 编码器: ['nvenc', 'qsv', 'amf']
[DEBUG] 正在测试编码器是否可用: hevc_nvenc...
[DEBUG] 硬件编码器 'hevc_nvenc' 可用。
[DEBUG] 已选择硬件编码器: hevc_nvenc
[DEBUG] 最终确定使用的编码器: hevc_nvenc
[DEBUG] app_cfg.proxy='http://127.0.0.1:2023'
[DEBUG] 无法连接 huggingface.co, 使用镜像替换: hf-mirror.com
[DEBUG] 以SRT字幕块翻译,每次翻译 50 条字幕块,翻译后暂停0.0s
[INFO] Starting call to 'videotrans.translator._openaicompat.OpenAICampat._item_task', this is the 1st time calling it.
[DEBUG] 字幕翻译:[self.ainame='openrouter',kwargs={'model': 'google/gemini-2.5-flash-lite', 'timeout': 300, 'temperature': 0.1, 'max_tokens': 8192}]
[INFO] Finished call to 'videotrans.translator._openaicompat.OpenAICampat._item_task' after 8.078(s), this was the 1st time calling it.
[DEBUG] 以SRT字幕块翻译,每次翻译 50 条字幕块,翻译后暂停0.0s
[INFO] Starting call to 'videotrans.translator._openaicompat.OpenAICampat._item_task', this is the 1st time calling it.
[DEBUG] 字幕翻译:[self.ainame='openrouter',kwargs={'model': 'google/gemini-2.5-flash-lite', 'timeout': 300, 'temperature': 0.1, 'max_tokens': 8192, 'reasoning_effort': 'high'}]
[INFO] Finished call to 'videotrans.translator._openaicompat.OpenAICampat._item_task' after 7.438(s), this was the 1st time calling it.
[DEBUG] 以SRT字幕块翻译,每次翻译 50 条字幕块,翻译后暂停0.0s
[INFO] Starting call to 'videotrans.translator._openaicompat.OpenAICampat._item_task', this is the 1st time calling it.
[DEBUG] 字幕翻译:[self.ainame='openrouter',kwargs={'model': 'google/gemini-2.5-flash', 'timeout': 300, 'temperature': 0.1, 'max_tokens': 8192, 'reasoning_effort': 'high'}]
[INFO] Finished call to 'videotrans.translator._openaicompat.OpenAICampat._item_task' after 7.547(s), this was the 1st time calling it.
[DEBUG] 以SRT字幕块翻译,每次翻译 50 条字幕块,翻译后暂停0.0s
[INFO] Starting call to 'videotrans.translator._openaicompat.OpenAICampat._item_task', this is the 1st time calling it.
[DEBUG] 字幕翻译:[self.ainame='openrouter',kwargs={'model': 'google/gemini-2.5-flash-lite', 'timeout': 300, 'temperature': 0.1, 'max_tokens': 8192}]
[INFO] Finished call to 'videotrans.translator._openaicompat.OpenAICampat._item_task' after 7.421(s), this was the 1st time calling it.
[DEBUG] 以SRT字幕块翻译,每次翻译 50 条字幕块,翻译后暂停0.0s
[INFO] Starting call to 'videotrans.translator._openaicompat.OpenAICampat._item_task', this is the 1st time calling it.
[DEBUG] 字幕翻译:[self.ainame='openrouter',kwargs={'model': 'gemini-2.5-flash-lite', 'timeout': 300, 'temperature': 0.1, 'max_tokens': 8192}]
[INFO] Finished call to 'videotrans.translator._openaicompat.OpenAICampat._item_task' after 7.578(s), this was the 1st time calling it.
[DEBUG] 以SRT字幕块翻译,每次翻译 50 条字幕块,翻译后暂停0.0s
[INFO] Starting call to 'videotrans.translator._openaicompat.OpenAICampat._item_task', this is the 1st time calling it.
[DEBUG] 字幕翻译:[self.ainame='openrouter',kwargs={'model': 'gemini-2.5-flash-lite', 'timeout': 300, 'temperature': 0.1, 'max_tokens': 8192}]
[INFO] Finished call to 'videotrans.translator._openaicompat.OpenAICampat._item_task' after 7.610(s), this was the 1st time calling it.

从你提供的日志来看,软件启动和各阶段翻译均正常完成(Finished call),未重现 'NoneType' object has no attribute 'get' 错误。这是正常运行的日志,不是错误日志。

请从 logs/ 目录中找到发生报错当天的日志文件(如 20260706.log),提供该文件中与 TestSrtTransAttributeError 相关的底部约 30 行内容,以及软件左上角的版本号。


Application started at 2026-07-06 07:51:41

1783295501:Loading resources...
1783295501:Loading main window...
1783295501:Initializing UI...
1783295501:SetupUI end...
1783295501:import recognition ...
1783295501:import tts ...
1783295501:import translate ...
1783295501:Get cache ...
1783295501:Set default value ...
1783295501:import voices list ...
1783295501:Set tts voice ...
[DEBUG] 上次缓存的角色:No,字幕嵌入类型:1,发音语言:en,目标语言:zh-cn,目标语言代码:None,模型:large-v3-turbo,TTS渠道[0]
1783295501:show main window ...
1783295501:Bind signal...
1783295501:set cursor...
1783295501:preload TTS win...
1783295502:preload STT win...
1783295502:preload translate srt win...
1783295502:end
[DEBUG] 平台: Windows。正在按优先级检测最佳的 'h264' 编码器: ['nvenc', 'qsv', 'amf']
[DEBUG] 正在测试编码器是否可用: h264_nvenc...
[DEBUG] 可用 Nvidia 显卡数: 1
[DEBUG] 找到 1 个 Nvidia GPUs, 耗时: 5s

[DEBUG] start 9 jobs
[DEBUG] 硬件编码器 'h2
......
eout': 300, 'temperature': 0.1, 'max_tokens': 8192}]
[INFO] Finished call to 'videotrans.translator._openaicompat.OpenAICampat._item_task' after 7.500(s), this was the 1st time calling it.
[DEBUG] 以SRT字幕块翻译,每次翻译 25 条字幕块,翻译后暂停0.0s
[INFO] Starting call to 'videotrans.translator._openaicompat.OpenAICampat._item_task', this is the 1st time calling it.
[DEBUG] 字幕翻译:[self.ainame='openrouter',kwargs={'model': 'gemini-2.5-flash-lite', 'timeout': 300, 'temperature': 0.1, 'max_tokens': 8192}]
[INFO] Finished call to 'videotrans.translator._openaicompat.OpenAICampat._item_task' after 7.375(s), this was the 1st time calling it.
[DEBUG] 以SRT字幕块翻译,每次翻译 25 条字幕块,翻译后暂停0.0s
[INFO] Starting call to 'videotrans.translator._openaicompat.OpenAICampat._item_task', this is the 1st time calling it.
[DEBUG] 字幕翻译:[self.ainame='openrouter',kwargs={'model': 'google/gemini-2.5-flash-lite', 'timeout': 300, 'temperature': 0.1, 'max_tokens': 8192}]
[INFO] Finished call to 'videotrans.translator._openaicompat.OpenAICampat._item_task' after 7.453(s), this was the 1st time calling it.
[DEBUG] 以纯文本行形式翻译,每次翻译10行,翻译后暂停0.0s
[INFO] Starting call to 'videotrans.translator._transapi.TransAPI._item_task', this is the 1st time calling it.
[DEBUG] 以SRT字幕块翻译,每次翻译 25 条字幕块,翻译后暂停0.0s
[INFO] Starting call to 'videotrans.translator._openaicompat.OpenAICampat._item_task', this is the 1st time calling it.
[DEBUG] 字幕翻译:[self.ainame='openrouter',kwargs={'model': 'google/gemini-2.5-flash-lite', 'timeout': 300, 'temperature': 0.1, 'max_tokens': 8192}]
[INFO] Finished call to 'videotrans.translator._openaicompat.OpenAICampat._item_task' after 7.593(s), this was the 1st time calling it.
[DEBUG] 以SRT字幕块翻译,每次翻译 25 条字幕块,翻译后暂停0.0s
[INFO] Starting call to 'videotrans.translator._openaicompat.OpenAICampat._item_task', this is the 1st time calling it.
[DEBUG] 字幕翻译:[self.ainame='openrouter',kwargs={'model': 'google/gemini-2.5-flash-lite', 'timeout': 300, 'temperature': 0.1, 'max_tokens': 8192}]
[INFO] Finished call to 'videotrans.translator._openaicompat.OpenAICampat._item_task' after 7.562(s), this was the 1st time calling it.
[DEBUG] 以纯文本行形式翻译,每次翻译10行,翻译后暂停0.0s
[INFO] Starting call to 'videotrans.translator._openaicompat.OpenAICampat._item_task', this is the 1st time calling it.
[DEBUG] 字幕翻译:[self.ainame='openrouter',kwargs={'model': 'google/gemini-2.5-flash-lite', 'timeout': 300, 'temperature': 0.1, 'max_tokens': 8192}]
[INFO] Finished call to 'videotrans.translator._openaicompat.OpenAICampat._item_task' after 7.328(s), this was the 1st time calling it.
[DEBUG] 以纯文本行形式翻译,每次翻译10行,翻译后暂停0.0s
[INFO] Starting call to 'videotrans.translator._openaicompat.OpenAICampat._item_task', this is the 1st time calling it.
[DEBUG] 字幕翻译:[self.ainame='openrouter',kwargs={'model': 'google/gemini-2.5-flash-lite', 'timeout': 300, 'temperature': 0.1, 'max_tokens': 8192}]
[INFO] Finished call to 'videotrans.translator._openaicompat.OpenAICampat._item_task' after 7.515(s), this was the 1st time calling it.

从你两次提供的日志来看,所有翻译测试(TestSrtTrans)均已成功完成(均显示 Finished call after ...),没有出现 'NoneType' object has no attribute 'get' 错误。这说明当前环节运行正常。

请确认以下两点:

  1. 错误出现的位置:这个错误是在“视频翻译”主流程中出现的,还是在“批量翻译SRT字幕”、“批量为字幕配音”等独立功能面板点击“开始”后出现的?
  2. 日志完整性:日志文件(logs/ 目录下当日日期的 .log 文件)通常包含多次任务记录。请打开该日志文件,翻到最末尾部分,寻找包含 ExceptionTracebackAttributeErrorRetryError 的行,并复制最后约 30 行内容。你提供的日志缺少了后半段可能的错误信息。

如果再次出现错误,请直接复制报错弹窗中的完整文本(包括 Traceback),而非只贴启动日志。

程序内部错误:'NoneType' object has no attribute 'get':Traceback (most recent call last):
File "videotrans\translator\_base.py", line 66, in run
File "videotrans\translator\_base.py", line 96, in _run_text
File "tenacity\__init__.py", line 338, in wrapped_f
File "tenacity\__init__.py", line 477, in call
File "tenacity\__init__.py", line 378, in iter
File "tenacity\__init__.py", line 421, in exc_check
tenacity.RetryError: RetryError[]

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "videotrans\util\TestSrtTrans.py", line 19, in run
File "videotrans\translator\_runner.py", line 63, in run
File "videotrans\translator\_base.py", line 72, in run
File "tenacity\__init__.py", line 480, in call
File "videotrans\translator\_openaicompat.py", line 79, in _item_task
AttributeError: 'NoneType' object has no attribute 'get'

这个错误发生在“批量翻译SRT字幕”的测试翻译环节,使用的是 OpenRouter 渠道(google/gemini-2.5-flash-lite 模型)的纯文本行模式(未选中“发送完整字幕”)。API 返回了空响应导致程序尝试调用 .get() 时报错。

解决方案

  1. 降低每批字幕行数:进入 菜单 → 高级选项 → 字幕翻译调整,将 AI翻译渠道每批字幕行数 改为 5,然后重新测试。
  2. 选中“发送完整字幕”:在主界面 Trans Channel 一行,勾选 发送完整字幕,该模式会附带行号和时间轴发送给 AI,通常更稳定。
  3. 更换模型:在 OpenRouter 设置中更换为更稳定的模型,例如 deepseek/deepseek-v4-flashopenai/gpt-4o-mini。当前使用的 gemini-2.5-flash-lite 存在偶发空响应问题。
  4. 检查 API Key 和余额:登录 OpenRouter 检查账户是否有足够的余额,以及该模型是否在你的账户中被启用。
  5. 临时更换渠道:直接改用 DeepSeek 或 OpenAI ChatGPT 翻译渠道(需对应 API Key),测试是否消失。

若以上操作后仍频繁出现,请提供 logs/ 目录下完整的错误日志(包含此次失败的完整堆栈)以及你使用的模型和每批行数。

程序内部错误:'NoneType' object has no attribute 'get':Traceback (most recent call last):
File "videotrans\translator\_base.py", line 69, in run
File "videotrans\translator\_base.py", line 143, in _run_srt
File "tenacity\__init__.py", line 338, in wrapped_f
File "tenacity\__init__.py", line 477, in call
File "tenacity\__init__.py", line 378, in iter
File "tenacity\__init__.py", line 421, in exc_check
tenacity.RetryError: RetryError[]

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "videotrans\util\TestSrtTrans.py", line 19, in run
File "videotrans\translator\_runner.py", line 63, in run
File "videotrans\translator\_base.py", line 72, in run
File "tenacity\__init__.py", line 480, in call
File "videotrans\translator\_openaicompat.py", line 79, in _item_task
AttributeError: 'NoneType' object has no attribute 'get'

你提供的错误堆栈显示,翻译任务在 _run_srt(SRT 字幕块模式,即勾选了“发送完整字幕”)下失败。关键点在于:

  • RetryError[]:执行了预设的重试次数(默认 5 次)后仍然失败,最终抛出。
  • AttributeError: 'NoneType' object has no attribute 'get':AP 返回了 None,代码在尝试解析时出错。

此问题表示 OpenRouter 渠道(模型 google/gemini-2.5-flash-lite)在反复重试后仍未返回有效数据。

请执行以下步骤

  1. 提供完整日志
    打开软件安装目录下的 logs/ 文件夹,找到发生错误当天的 .log 文件(如 20260706.log),复制该文件末尾约 30-50 行包含此次错误堆栈的完整内容。你之前仅提供了堆栈起点和结尾,缺少中间的重试过程和最终错误详情。这能帮助定位是网络超时、API Key 无效还是模型不兼容。
  2. 临时更换翻译渠道与模型
    在问题解决前,请:

    • 将翻译渠道切换为 DeepSeek(需配置 API Key),它对中国大陆网络最友好且不易空响应。
    • 若仍使用 OpenRouter,请将模型换为 openai/gpt-4o-minideepseek/deepseek-v4-flash,这些模型更稳定。
  3. 调整参数

    • 菜单 → 高级选项 → 字幕翻译调整 中,将 AI翻译渠道每批字幕行数 减少到 105
    • 确认 发送完整字幕 已勾选(你的日志显示 _run_srt 已启用该模式)。
  4. 检查 OpenRouter 账户
    登录 openrouter.ai,确认:

    • API Key 有效且未过期。
    • 账户余额充足。
    • 模型 google/gemini-2.5-flash-lite 未被禁用或下架。

参考文档

请先提供完整日志片段,以便进一步诊断。

程序内部错误:'NoneType' object has no attribute 'get':Traceback (most recent call last):
File "videotrans\translator\_base.py", line 69, in run
File "videotrans\translator\_base.py", line 143, in _run_srt
File "tenacity\__init__.py", line 338, in wrapped_f
File "tenacity\__init__.py", line 477, in call
File "tenacity\__init__.py", line 378, in iter
File "tenacity\__init__.py", line 421, in exc_check
tenacity.RetryError: RetryError[]

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "videotrans\util\TestSrtTrans.py", line 19, in run
File "videotrans\translator\_runner.py", line 63, in run
File "videotrans\translator\_base.py", line 72, in run
File "tenacity\__init__.py", line 480, in call
File "videotrans\translator\_openaicompat.py", line 79, in _item_task
AttributeError: 'NoneType' object has no attribute 'get'

你提供的错误堆栈表明翻译时 API 返回了空内容。根据知识库,此问题的根本原因是翻译渠道(OpenRouter 的 google/gemini-2.5-flash-lite 模型)在多次重试后均未返回有效响应,最终导致 AttributeError: 'NoneType' object has no attribute 'get'

请按顺序尝试以下方法:

  1. 更换翻译渠道或模型

    • 将翻译渠道改为 DeepSeek(需在菜单-翻译设置中配置 API Key),它对国内网络友好且不易空响应。
    • 如果继续使用 OpenRouter,请将模型换为 openai/gpt-4o-minideepseek/deepseek-v4-flash,这些模型更稳定。
  2. 降低每批字幕行数并检查参数

    • 进入 菜单 → 高级选项 → 字幕翻译调整,将 AI翻译渠道每批字幕行数 改为 5
    • 确保已勾选 发送完整字幕(你的日志显示已启用,但降低批次能减轻API压力)。
  3. 检查 OpenRouter 账户

    • 登录 openrouter.ai 确认:

      • API Key 未过期
      • 账户余额充足
      • 所选模型未被下架或禁用
  4. 尝试切换其他免费渠道

    • 临时改用 谷歌翻译微软翻译(免费渠道,无需配置),测试是否正常,以排除软件自身问题。

如果以上方法无效,请提供完整日志:

打开软件目录下的 logs/ 文件夹,找到发生错误当天的 .log 文件(如 20260706.log),复制文件末尾 至少 30 行 内容,并标注软件左上角的版本号。这将帮助判断是API超时、密钥错误还是其他网络问题。

Post Your Reply
Open source and free maintenance is not easy. If this project is helpful to you, please consider making a small donation to help the project continue to maintain and update. Dondate: ko-fi.com/jianchang512

Related resource