Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/342.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 正在下载带有urllib[Errno 2]的图像没有这样的文件或目录_Python_Windows_Urllib - Fatal编程技术网

Python 正在下载带有urllib[Errno 2]的图像没有这样的文件或目录

Python 正在下载带有urllib[Errno 2]的图像没有这样的文件或目录,python,windows,urllib,Python,Windows,Urllib,我正在制作一个脚本,用python 3.6从某个站点下载png文件 导入URL库请求 name=“gato”+“.png” urllib.request.urlretrieve('https://cdn.pixabay.com/photo/2017/09/01/00/15/png-2702691_960_720.png,名称) 但我以[Errno 2]结尾,没有这样的文件或目录 如果我使用 urllib.request.urlretrieve('https://cdn.pixabay.com/p

我正在制作一个脚本,用python 3.6从某个站点下载png文件

导入URL库请求

name=“gato”+“.png”

urllib.request.urlretrieve('https://cdn.pixabay.com/photo/2017/09/01/00/15/png-2702691_960_720.png,名称)

但我以[Errno 2]结尾,没有这样的文件或目录 如果我使用
urllib.request.urlretrieve('https://cdn.pixabay.com/photo/2017/09/01/00/15/png-2702691_960_720.png“,”name.png“

我没有得到这样的错误,这不是最好的答案,但它也一样。祝你好运

import requests

imageurl = 'https://cdn.pixabay.com/photo/2017/09/01/00/15/png-2702691_960_720.png'
file = 'gato.png'

response = requests.get(imageurl)

with open(file, 'wb') as f:
    f.write(response.content)