I have a python program that reads an mp3 and returns a URL of it's album art. However, when I download that image using requests and then use mutagen to set that image as the album art of my mp3 it doesn't return any errors but the album cover is unchanged on my mp3. The weird thing, though, is that some images that I manually download from my browser work just fine.
Here is my code:
from mutagen.mp3 import MP3
from mutagen.id3 import APIC
import requests
audio = MP3(filePath)
r = requests.get("https://is5-ssl.mzstatic.com/image/thumb/Music124/v4/fb/58/03/fb5803f7-071b-adc2-73d1-928a772234ac/00602547996091.rgb.jpg/300x300bb.jpg") #this is the URL that is automatically generated by my program.
file = open("temp-album-art.jpg", "wb")
file.write(r.content)
file.close()
audio.tags.add(APIC(encoding=3,
mime='image/jpeg',
type=3,
desc=u'Cover',
data=open("temp-album-art.jpg", 'rb').read()
))
audio.save()
The URL that my program returns is: "https://is5-ssl.mzstatic.com/image/thumb/Music124/v4/fb/58/03/fb5803f7-071b-adc2-73d1-928a772234ac/00602547996091.rgb.jpg/300x300bb.jpg". It gets saved as "temp-album-art.jpg" just fine but doesn't work when trying to use it as the album art using mutagen. It also doesn't work when manually downloading it from my browser.
This is the image that does work "https://www.hollywoodreporter.com/wp-content/uploads/2013/03/30stm_love_lust_album_art_p.jpg?w=2000&h=1126&crop=1" though it downloaded as a .webp file and so I used https://ezgif.com/webp-to-jpg to convert it to a jpeg. Interestingly, it does not work when downloaded by my program using requests.
Does the problem stem from some kind of meta data in the images? If not, why the discrepancy?

There could be a few different reasons why the album art is not being set correctly for some images. One possibility is that the image file you are using is not in a format that is supported by Mutagen. Mutagen supports JPEG, PNG, and GIF image formats, but not all image files in those formats may be compatible with Mutagen. It's possible that some of the images you are trying to use have different metadata or compression settings that make them incompatible with Mutagen.
Another possibility is that the image data you are passing to Mutagen is not correctly formatted or is not being encoded correctly. The data that you pass to Mutagen should be a bytes object containing the image data in the appropriate format. It's possible that there is some issue with how you are reading or encoding the image data that is causing it to be incompatible with Mutagen.
To help troubleshoot the issue, you can try printing out some information about the image files you are using, such as their format, size, and metadata, using Python libraries like Pillow or ExifTool. This can help you determine if there are any differences between the images that are working and the ones that are not, and may give you some clues as to what the issue could be.
You could also try using a different library to set the album art, such as eyeD3 or pytaglib, to see if you get different results with those libraries. Alternatively, you could try using a different method to download the images, such as using a different Python library like urllib or wget, or using a different program or web service to download the images manually, to see if that makes a difference.