可以使用Python的Pillow库来解码图像并将其显示。例如:
import requests
from PIL import Image
from io import BytesIO
response = requests.get(url)
img = Image.open(BytesIO(response.content))
img.show()
在这里,我们首先使用requests模块从API响应中获取图像。然后,使用BytesIO对象将图像数据流转换为图像对象。最后,使用img.show()方法显示图像。
如果您还是遇到问题,可以在调试期间打印出返回的响应内容,以便了解图像数据是否正在正确下载。