Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Download a file to a specific folder with python

Tags:

python

urllib

I am trying to download a particular file to a specific folder on my hardisk. I am using IronPython 2.7 and urllib module.

I tried downloading the file with the following code:

import urllib

response = urllib.urlretrieve(someURL, 'C:/someFolder')
html = response.read()
response.close()  

But when upper code is ran, I get the following error message:

Runtime error (IOException): Access to the path 'D:\someFolder' is denied.
Traceback:
line 91, in urlretrieve, "C:\Program Files\IronPython\Lib\urllib.py"
line 9, in script
line 241, in retrieve, "C:\Program Files\IronPython\Lib\urllib.py"

I tried entering the Attributes of my "someFolder", and found out the "Read-only" is checked. I unchecked it, clicked "Apply" and "Ok". But when I come back again, "Read-only" is checked again. No matter how many times I uncheck it and confirm, it the "sameFolder" still remains "Read-only". Is this the reason why I am getting the upper error message?

Hot to fix it? I tried moving the "someFolder" to other partitions, but still for some reason I can not uncheck the "Read-only" attribute (I can, but it just keeps coming back).

Thank you for the reply.

I forgot to say that I use Windows XP 32 bit.

EDIT: I checked if "someFolder" is writable and it is. The following code:

print os.access("C:/someFolder", os.W_OK)

returns: True.

like image 844
marco Avatar asked Sep 28 '15 22:09

marco


1 Answers

You may want to use this instead:

import os
import urllib

fullfilename = os.path.join('C:/somedir', 'test.html')
urllib.urlretrieve("http://www.google.com", fullfilename)
like image 56
Pedro Lobito Avatar answered Oct 25 '22 12:10

Pedro Lobito