I'm getting this error :
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Python34\lib\tkinter\__init__.py", line 1538, in __call__
return self.func(*args)
File "C:/Users/Marc/Documents/Programmation/Python/Llamachat/Llamachat/Llamachat.py", line 32, in download
with open(place_to_save, 'wb') as file:
PermissionError: [Errno 13] Permission denied: '/goodbye.txt'
When running this :
def download():
# get selected line index
index = films_list.curselection()[0]
# get the line's text
selected_text = films_list.get(index)
directory = filedialog.askdirectory(parent=root,
title="Choose where to save your movie")
place_to_save = directory + '/' + selected_text
print(directory, selected_text, place_to_save)
with open(place_to_save, 'wb') as file:
connect.retrbinary('RETR ' + selected_text, file.write)
tk.messagebox.showwarning('File downloaded',
'Your movie has been successfully downloaded!'
'\nAnd saved where you asked us to save it!!')
Can someone tell me what I am doing wrong?
Specs : Python 3.4.4 x86 Windows 10 x64
place_to_save
be simplygoodbye.txt
? I'm not sure how Windows would behave, but on Linux you'll be writing to root dir (/
), and that's always a bad idea. Instead of manual string manipulation you should useos.path.join(directory, selected_text)
. – Northernmostopen(place_to_save, 'w+')
instead ofopen(place_to_save, 'wb')
. I remember seeing some other SO posts about the same issue, – Camailopen('/goodbye.txt', 'wb')
. If this also raises, thentkinter
is irrelevant and should be removed as a tag. This should be tagged with the OS, as that is relevant. – Basiliskplace_to_save
is what you think it is. – Husbandryprint(directory, selected_text, place_to_save)
? My guess is thatdirectory
is an empty string for some reason. I would try addinginitialdir=r'c:/'
tofiledialog.askdirectory
call. – Brittenybrittinghamprint((directory, selected_text, place_to_save))
, as that will print a tuple, which will show you the representation of those strings. – Egocentric