简体   繁体   中英

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 eg

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

And then:

im1 = im1.save(image_path)

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")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM