When I try to download a file in python 3.3.2 with the urllib.request.urlretrieve function, I get the following error:
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Python33\lib\tkinter\__init__.py", line 1475, in __call__
return self.func(*args)
File "C:\Python33\lib\site-packages\downloader.py", line 17, in startdownload
urllib.request.urlretrieve(url, file, reporthook)
File "C:\Python33\lib\urllib\request.py", line 191, in urlretrieve
tfp = open(filename, 'wb')
PermissionError: [Errno 13] Permission denied: '.\\tmp'
I'm trying to save the file in the dir tmp on my desktop. I'm using the following code in the module "downloader.py":
def download(url, file):
import urllib.request, tkinter, os, time
from tkinter import ttk
def reporthook(blocknum, blocksize, totalsize):
readsofar = blocknum*blocksize
percent = readsofar * 1e2 / totalsize
GUI.title(str(int(percent)) + "% done")
PROGRESS["value"] = percent
PROGRESS.update()
def startdownload():
BUTTON.destroy()
for y in range(70, 40, -1):
time.sleep(0.1)
GUI.geometry("500x"+str(y))
GUI.update()
urllib.request.urlretrieve(url, file, reporthook)
GUI.destroy()
GUI = tkinter.Tk()
GUI.resizable(0,0)
GUI.title("Click the download button to start downloading!")
GUI.geometry("500x70")
PROGRESS = ttk.Progressbar(GUI, length=480)
PROGRESS.place(x=10, y=10)
BUTTON = ttk.Button(GUI, text="start download", command=startdownload)
BUTTON.place(x=200, y=40)
GUI.mainloop()
I don't know how to give python the permissions to download a file. Or is something wrong in the code?
Thank you for your help!
file
in thedownload
function is not an empty string. I think it's trying to write to .\\tmp wich is a directory, not a file name, so it can't, access denied. EDIT: I checked on Linux, if this was the case, you should have aIOError: [Errno 21] Is a directory: tmp
– Redolent