问题描述:在API调用中,无法显示照片。
解决方法:
示例代码(以Python为例):
import requests
from PIL import Image
# API调用示例
response = requests.get("https://api.example.com/photos/1")
data = response.json()
# 检查API响应是否成功
if response.status_code == 200:
# 获取照片数据
photo_data = data["photo_data"]
# 将照片数据保存为图片文件
with open("photo.jpg", "wb") as f:
f.write(photo_data)
# 打开并显示照片
image = Image.open("photo.jpg")
image.show()
else:
print("API调用失败:" + str(response.status_code))
请根据实际情况修改示例代码中的URL、参数和文件保存路径等。
下一篇:API调用成功,但未返回数据