Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/298.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何从Unsplash API返回的URL获取图像?_Python_Python 3.x_Python Requests - Fatal编程技术网

Python 如何从Unsplash API返回的URL获取图像?

Python 如何从Unsplash API返回的URL获取图像?,python,python-3.x,python-requests,Python,Python 3.x,Python Requests,在这里,我的代码运行并获取图像的url,但如何在小窗口中自动打开照片。linkFetch()函数实际获取图像链接,我希望imageFetch()实际打开照片。我不熟悉使用API,所以任何帮助都会很有用。我已经尝试使用另一个request.get(),但可能使用不正确。其他解决方案似乎希望在我只想打开的地方无限期地下载图像 注意:MyAccessKey将替换我的实际密钥您必须首先通过发送请求获取图像数据,然后将其传递给以显示图像 import requests def linkFetch():

在这里,我的代码运行并获取图像的url,但如何在小窗口中自动打开照片。linkFetch()函数实际获取图像链接,我希望imageFetch()实际打开照片。我不熟悉使用API,所以任何帮助都会很有用。我已经尝试使用另一个request.get(),但可能使用不正确。其他解决方案似乎希望在我只想打开的地方无限期地下载图像


注意:MyAccessKey将替换我的实际密钥

您必须首先通过发送请求获取图像数据,然后将其传递给以显示图像

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

您必须首先通过发送请求获取图像数据,然后将其传递给以显示图像

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

最后一行返回错误“无法识别图像文件”。最后一行返回错误“无法识别图像文件”。您可以查看Python的GUI框架。Python已经内置了Tkinter来实现这一点。另一种方法是使用库在默认查看器中打开。您可以查看Python的GUI框架。Python已经内置了Tkinter来实现这一点。另一种方法是使用库在默认查看器中打开。