Search code examples
pythonimageapispotify

Saving image from API Endpoint with no filetype, in python


I'm trying to save images from the Spotify API

I get album art in the form of a link:

https://i.scdn.co/image/ab67616d00004851c96f7c7b077c224975b4c5ce

I think it's a jpg file.

I run into errors in trying to display or save this in python.

I'm not even sure how I'm meant to format something like:

Do I need str around the link? str(https://i.scdn.co/image/ab67616d00004851c96f7c7b077c224975b4c5ce)

Or should I create a new variable e.g.

image_path = 'https://i.scdn.co/image/ab67616d00004851c96f7c7b077c224975b4c5ce'

And then:

im1 = im1.save(image_path)


Solution

  • Your second suggestion should work with an addition of actually downloading the image using urllib.request:

    import urllib.request
    
    image_path = 'https://i.scdn.co/image/ab67616d00004851c96f7c7b077c224975b4c5ce'
    
    urllib.request.urlretrieve(image_path, "image.jpg")