import requests
def linkFetch():
url = "https://api.unsplash.com/photos/random/?client_id=MyAccessKey"
response = requests.get(url)
data = response.json()["urls"]["raw"]
return data
def imageFetch(data):
print(data)
imageFetch(linkFetch())
在这里,我的代码运行并获取图像的url,但我如何在小窗口中自动打开照片。linkFetch()函数实际获取图像链接,我希望imageFetch()实际打开照片。我刚开始使用apis,所以任何帮助都会很有用。我已经尝试使用另一个request.get(),但是我可能用错了。其他解决方案似乎想要无限期地下载图像,而我只想打开它。
注意: MyAccessKey替换了我的实际密钥
发布于 2020-03-31 16:01:52
您必须首先通过发送请求来获取图像数据,然后将其传递给pillow package以显示图像。
from io import BytesIO
from PIL import Image
import requests
img_url = imageFetch(linkFetch())
response = requests.get(img_url)
img = Image.open(BytesIO(response.content))
img.show()
https://stackoverflow.com/questions/60945712
复制相似问题