0

I am creating a script which can access and set mp3 metadata using the spotipy and music_tag python libraries. One part of this involves accessing album cover artwork through spotify to add to local mp3 files. On some image links, I get either one of these two errors:

  • URLError(TimeoutError(10060, 'A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond', None, 10060, None)))
  • URLError(gaierror(11001, 'getaddrinfo failed')))

Here are some examples of links that raise errors, copied from my log output:

  • \<urlopen error \[WinError 10060\] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond\> \[1759\] - DEVASTATED \_ Joey Bada$$ https://i.scdn.co/image/ab67616d0000b2736a3c1e51a7d2a2a7fbe172a1

  • \<urlopen error \[WinError 10060\] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond\> \[1760\] - Alright \_ Kendrick Lamar https://i.scdn.co/image/ab67616d0000b273cdb645498cd3d8a2db4d05e1

  • \<urlopen error \[Errno 11001\] getaddrinfo failed\> \[1955\] - Sierra Leone \_ Frank Ocean https://i.scdn.co/image/ab67616d0000b2737aede4855f6d0d738012e2e5

  • \<urlopen error \[Errno 11001\] getaddrinfo failed\> \[1956\] - Super Rich Kids \_ Frank Ocean, Earl Sweatshirt https://i.scdn.co/image/ab67616d0000b2737aede4855f6d0d738012e2e5

  • \<urlopen error \[Errno 11001\] getaddrinfo failed\> \[1957\] - White \_ Frank Ocean, John Mayer https://i.scdn.co/image/ab67616d0000b2737aede4855f6d0d738012e2e5

Interestingly, this only happens for a small fraction of the images, and I am always able to access them through chrome, so the links are valid. I've tried increasing the amount of max_retries as per this post, but still no luck. Here is the function where I get the error:

def set_metadata_musictag(metadata_dict:dict, mp3_fpath:str) -> None:
    
    audio = music_tag.load_file(mp3_fpath)
    audio['year'] = metadata_dict['year_released']
    audio['artist'] = metadata_dict['artist']
    audio['album'] = metadata_dict['album']
    audio['albumartist'] = metadata_dict['album_artist']
    audio['tracknumber'] = metadata_dict['track_number']
    audio['tracktitle'] = metadata_dict['title']

    s = requests.Session()
    retries = Retry(total=4,
                    backoff_factor=0.1,
                    status_forcelist=[ 500, 502, 503, 504 ],
                    raise_on_status=True)
    s.mount('http://', HTTPAdapter(max_retries=retries))

    try:
        img_bytes = s.get(metadata_dict['album_img_url'], timeout=100000).content
        audio['artwork'] = img_bytes
    except:
        print("FAILED to get album cover artwork")

    audio.save()

I'm happy to provide more information as necessary

Arya n
  • 13
  • 5

0 Answers0