You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何解决eyed3库报错AttributeError: 'NoneType' object has no attribute 'tag'

问题分析与解决

从错误日志能明确看到,eyed3.core.load(new_file)返回了None,这说明eyed3没能成功加载目标MP3文件,后续直接访问mySong.tag自然会抛出AttributeError。

解决步骤

  1. 先校验加载结果
    在访问mySong.tag之前,必须先判断mySong是否为None,避免空对象操作:

    if new_file.exists():
        print(f'{data[i][0]} has been\033[1;32;40m successfully downloaded.\033[m  ')
        mySong = eyed3.core.load(new_file)
        print(new_file)
        print(mySong)
        
        # 先判断mySong是否加载成功
        if mySong is None:
            print(f"Failed to load {new_file}, skip tagging")
            continue
            
        if mySong.tag is None:
            mySong.initTag()
        mySong.tag.images.set(type_=3, img_data=None, mime_type=None, description=None, img_url=data[i][3])
        mySong.tag.save()
    
  2. 排查加载失败根源

    • 检查MP3文件完整性:用系统播放器或其他音乐工具打开文件,确认文件没有损坏
    • 核对文件路径与名称:打印new_file的绝对路径,确认和实际文件路径一致;注意错误日志中原文件名是I Ain't Worried.mp3,但代码输出的是I Aint Worried.mp3,可能存在下载时的字符丢失问题
    • 更新eyed3版本:旧版本对部分MP3编码支持有限,执行pip install --upgrade eyed3更新到最新版
    • 检查文件编码:若文件采用eyed3不支持的编码,可尝试用ffmpeg等工具重新编码后再处理

内容的提问来源于stack exchange,提问作者Melabr

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.08 00:20:38