pythonmp3nonetypeeyed3

How to solve AttributeError: 'NoneType' object has no attribute 'tag'


I'm using the eyed3 and this is a part of my long code:

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)
            if (mySong.tag == None):
                mySong.initTag()
            mySong.tag.images.set(type_=3, img_data=None ,mine_type=None,description=None,img_url=data[i][3] )
            mySong.tag.save()

And I'm getting this error thousands of times:

I Ain't Worried has been successfully downloaded.
C:\Users\elabr\Desktop\Folder\I Aint Worried.mp3
None
Traceback (most recent call last):
  File "C:\Users\elabr\youtube_api.py", line 60, in <module>
    if (mySong.tag == None):
AttributeError: 'NoneType' object has no attribute 'tag'

I dont't know what im doing wrong tbh and would really appreaciate some help pls guys.


Solution

  • Alright i solved this and forgot to post an update. So the issue was with the file as people suggested, sometimes the file can be in .mp3 but its not actually encoded this way. You gotta open it in notepad and check if its really mp3 by its content.