繁体   English   中英

从 API 端点保存图像,没有文件类型,在 python

[英]Saving image from API Endpoint with no filetype, in python

我正在尝试从 Spotify API 保存图像

我以链接的形式获得专辑封面:

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

我认为这是一个jpg文件。

我在尝试在 python 中显示或保存时遇到错误。

我什至不确定我应该如何格式化:

我需要链接周围的 str 吗? str(https://i.scdn.co/image/ab67616d00004851c96f7c7b077c224975b4c5ce)

或者我应该创建一个新变量,例如

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

接着:

im1 = im1.save(image_path)

您的第二个建议应该与使用urllib.request实际下载图像一起使用:

import urllib.request

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

urllib.request.urlretrieve(image_path, "image.jpg")

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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