Reputation: 20915
I tried to download Google's logo with
import os, urllib
folderName = 'downloadedImages'
if not os.path.exists(folderName):
os.makedirs(folderName)
urllib.urlretrieve(https://www.google.com/images/srpr/logo3w.png, './' + folderName + '/')
However, I receive an error: IOError: [Errno 21] Is a directory: './downloadedImages/'
.
Why?
Upvotes: 0
Views: 2226
Reputation: 53386
Second parameter to urllib.urlretrieve()
need to a file name rather than directory.
Upvotes: 0
Reputation: 44454
Check the documentation: http://docs.python.org/library/urllib.html#urllib.urlretrieve
You need to give the filename, not the directory path:
urllib.urlretrieve("path/to/resource", os.path.join(folderName, "filename.jpg"))
Upvotes: 2
Reputation: 137517
Because of just what the error says: What you've provided in the second argument is a directory. It needs to be the local (destination) filename.
The python docs state (emphasis mine):
The second argument, if present, specifies the file location to copy to (if absent, the location will be a tempfile with a generated name).
Upvotes: 2