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
To fix PermissionError: [Errno 13] Permission denied with Python open, we should make sure the path we call open with is a file. to make sure that the path is a path to a file with os. path. isfile before we call open to open the file at the path .
Permission denied simply means the system is not having permission to write the file to that folder. Give permissions to the folder using "sudo chmod 777 " from terminal and try to run it. It worked for me.
Set file permissions (chmod) To change file permissions, you can use os. chmod(). You can bitwise OR the following options to set the permissions the way you want. These values come from the stat package: Python stat package documentation.
os. chmod(path, 0444) is the Python command for changing file permissions in Python 2. x. For a combined Python 2 and Python 3 solution, change 0444 to 0o444 .
This happens if you are trying to open a file, but your path is a folder.
This can happen easily by mistake.
To defend against that, use:
import os path = r"my/path/to/file.txt" assert os.path.isfile(path) with open(path, "r") as f: pass
The assertion will fail if the path is actually of a folder.
There are basically three main methods of achieving administrator execution
privileges on Windows.
cmd.exe
python
executable (Not recommended)A) Running cmd.exe
as and admin
Since in Windows there is no sudo
command you have to run the terminal (cmd.exe
) as an administrator to achieve to level of permissions equivalent to sudo
. You can do this two ways:
Manually
cmd.exe
in C:\Windows\system32
Run as Administrator
C:\Windows\system32
Via key shortcuts
alt
and ctrl
usually) + X
.Command Prompt (Admin)
By doing that you are running as Admin so this problem should not persist
B) Creating shortcut with elevated privileges
python.exe
Properties
"C:\path_to\python.exe" C:\path_to\your_script.py"
Answer contributed by delphifirst in this question
C) Changing the permissions on the python
executable (Not recommended)
This is a possibility but I highly discourage you from doing so.
It just involves finding the python
executable and setting it to run as administrator every time. Can and probably will cause problems with things like file creation (they will be admin only) or possibly modules that require NOT being an admin to run.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With