Reputation: 250
I am trying to download set of files from a website into my local drive in Windows using Python 2.7 but getting permission denied error:
One of the examples is below:
urllib.urlretrieve('http://www.renderx.com/files/demos/examples/Fund.pdf',"c://python")
Traceback (most recent call last):
File "<pyshell#151>", line 1, in <module>
urllib.urlretrieve('http://www.renderx.com/files/demos/examples/Fund.pdf',"c://python")
File "C:\Python\Python27\lib\urllib.py", line 94, in urlretrieve
return _urlopener.retrieve(url, filename, reporthook, data)
File "C:\Python\Python27\lib\urllib.py", line 244, in retrieve
tfp = open(filename, 'wb')
IOError: [Errno 13] Permission denied: 'c://python'
When I don't specify a path, it downloads files (without any issue) into path where Python is installed C://pyhton//Python27... But I want to download all the files in a specific folder. Can you please help me in the issue?
Upvotes: 1
Views: 6248
Reputation: 21740
If you don't specify a path, python will take the path of the .py
file you runned.
As the you provided the second argument the folder name(c://python
) that already exist, it probably tried to replace your python directory(c://Python
).
You can give the second argument a filename
for the downloading file(if same file already exist you may get error). ie:
urllib.urlretrieve('http://www.renderx.com/files/demos/examples/Fund.pdf',
"c://python//fund.pdf")
I assume this will store the file fund.pdf
in the python
directory
Upvotes: 1