#5941 程序内部错误:'str' object has no attribute 'get':Traceback (most recent call last): File

13.113* Posted at: 23 hours ago

程序内部错误:'str' object has no attribute 'get':Traceback (most recent call last):
File "videotrans\translator\_base.py", line 71, in run
File "videotrans\translator\_base.py", line 200, 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 74, in run
File "tenacity\__init__.py", line 480, in call
File "videotrans\translator\_openaicompat.py", line 82, in _item_task
AttributeError: 'str' object has no attribute 'get'


=
system:Windows-10-10.0.26100-SP0
version:v4.05
frozen:True
language:zh
root_dir:D:/baiduyunDownload/win-pyvideotrans-v4.05-0711

5 Replies

此错误是由于翻译渠道配置参数类型错误导致的。_openaicompat.py 中期望一个字典对象,但收到了字符串。

解决方案

  1. 检查 AI 翻译渠道配置

    • 进入 菜单 → 翻译设置 → 兼容AI/本地模型(或其他你正在使用的 AI 翻译渠道),确认 API 地址模型名称 填写正确,且格式为 URL 和字符串,中间无多余空格、换行。
  2. 检查高级选项中的温度值

    • 进入 菜单 → 工具/选项 → 高级选项 → 字幕翻译调整,确保 AI翻译模型温度值 为数字(如 1.0),不能是字符串如 "1.0"
  3. 重置配置文件

    • 关闭软件,将 软件目录/videotrans/params.json 文件重命名或删除(建议先备份),然后重新启动软件,重新填写相关 API 密钥和配置。
  4. 检查自定义参数:如果使用了自定义 ffmpeg 参数或翻译提示词,暂时清空测试。

如果上述步骤无法解决,请提供 logs/ 下最新日志文件中的约30行报错内容,并说明你使用的是哪个翻译渠道(如 DeepSeek、OpenAI、本地大模型等)。

日志 DEBUG:VideoTrans:以SRT字幕块翻译,每次翻译 50 条字幕块,翻译后暂停0.0s
[INFO] Starting call to 'videotrans.translator._openaicompat.OpenAICampat._item_task', this is the 1st time calling it.
INFO:VideoTrans:Starting call to 'videotrans.translator._openaicompat.OpenAICampat._item_task', this is the 1st time calling it.
[DEBUG] 字幕翻译:[self.ainame='chatgpt',kwargs={'model': 'deepseek-v4-flash', 'timeout': 300, 'temperature': 0.1, 'max_tokens': 163840, 'reasoning_effort': 'medium'}]
DEBUG:VideoTrans:字幕翻译:[self.ainame='chatgpt',kwargs={'model': 'deepseek-v4-flash', 'timeout': 300, 'temperature': 0.1, 'max_tokens': 163840, 'reasoning_effort': 'medium'}]
[INFO] Finished call to 'videotrans.translator._openaicompat.OpenAICampat._item_task' after 2.515(s), this was the 1st time calling it.
INFO:VideoTrans:Finished call to 'videotrans.translator._openaicompat.OpenAICampat._item_task' after 2.515(s), this was the 1st time calling it.

根据日志分析:翻译调用虽然显示 Finished,但参数 reasoning_effort: 'medium' 不是所有模型都支持,且温度值 0.1 可能被错误地写为字符串。这会导致底层代码在解析配置时将温度值视为字符串而非数字,进而触发 'str' object has no attribute 'get' 错误。

请按以下顺序排查:

  1. 进入 菜单 → 翻译设置 → 兼容AI/本地模型

    • 确保 模型名称 填写的 deepseek-v4-flash 是纯文本。
    • 确保 API地址(如 https://api.deepseek.com/v1)正确。
    • 确保 温度值 填的是数字(例如 0.1),不能带引号或空格。
  2. 检查高级选项中的温度设置

    • 菜单 → 工具 → 高级选项 → 字幕翻译调整
    • 确保 AI翻译模型温度值数字(如 1.0),不是字符串。
  3. 移除可能冲突的参数

    • reasoning_effort 参数对 DeepSeek 渠道是多余的,请检查 params.json 中是否有自定义配置导致错误。
    • 建议先删除 videotrans/params.json 文件(备份后删除),重新启动软件,再填入一次密钥和配置。
  4. 取消勾选 发送完整字幕

    • 在主界面翻译区域,取消勾选 发送完整字幕,强制逐行翻译,排除上下文干扰。
  5. 确认软件版本

    • 你的版本是 v4.05,建议更新到最新 v4.06 以修复已知问题。

执行上述步骤后如果问题仍然存在,请提供 logs/ 目录下最新日志文件完整内容的前60行和后60行,并说明你使用的具体翻译渠道名称(如“兼容AI/本地模型”或“DeepSeek”)。

我是用的中转站 不知道为啥不行

中转站(第三方代理 API)与软件交互时,reasoning_effort 这个参数通常不被普通中转站支持,导致底层代码收到非预期的响应格式。

请按以下步骤处理:


1. 清除 reasoning_effort 参数

  • 关闭软件。
  • 进入软件根目录 videotrans/,找到 params.json 文件(建议先备份到桌面)。
  • 用记事本打开,搜索 reasoning_effort 字段,整行删除(包括前面的逗号,保证 JSON 格式正确)。
  • 保存文件,重新启动软件。

2. 确认 API 地址与模型名

  • 进入 菜单 → 翻译设置 → 兼容AI/本地模型(或你使用的中转站对应的渠道面板)。
  • API 地址:必须完整,例如 https://api.your-proxy.com/v1(末尾不要加 /chat/completions)。
  • 模型名称:必须填写中转站支持的模型名,如 deepseek-v4-flashgpt-4o-mini。如果不确定,先改为 gpt-3.5-turbo 测试。
  • 温度值:填写纯数字 1.0(不要带引号)。

3. 关闭“发送完整字幕”与“LLM重新断句”

  • 在主界面翻译区域,取消勾选 发送完整字幕
  • 在语音识别区域,确认 重新断句 选为 默认断句(不是 LLM重新断句)。

4. 验证中转站连通性

  • 进入 菜单 → 工具 → 测试连接,选择同一个渠道,点击测试。如果失败,说明 API 地址、密钥或模型名配置有误,请咨询您的中转站提供商。

5. 降级测试

  • 如果上述步骤无效,暂时改用软件内置的 Microsoft 翻译Google 翻译 作为翻译渠道,确认软件基本翻译功能正常,排除中转站兼容性问题。

如果报错依然出现,请提供 params.json 中翻译渠道部分的完整内容(可抹去密钥),以及中转站的 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 via ko-fi.com

Dondate via PayPal

Related resource