Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IOError: [Errno 13] Permission denied

Tags:

python

I have this piece of code to create a .json file to store python data. When i run it in my server i get this error:

IOError: [Errno 13] Permission denied: 'juliodantas2015.json' at line with open(output_file, 'wb') as fp:

Python code:

fich_input='juliodantas2015.txt'
output_file= fich_input.strip('.txt')+'.json'
import json
with open(output_file, 'wb') as fp:
    json.dump('yes', fp)

In command line i typed chmod 777 *.py but still not working. How can i fix this ?

like image 403
João Pedro Avatar asked Mar 29 '15 16:03

João Pedro


People also ask

How do I fix errno 13 Permission denied in Python?

The PermissionError: [errno 13] permission denied error occurs when you try to access a file from Python without having the necessary permissions. To fix this error, use the chmod or chown command to change the permissions of the file so that the right user and/or group can access the file.

How do I fix Python permission denied error?

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.

How do I fix 13 permissions denied in Linux?

To fix the permission denied error in Linux, one needs to change the file permission of the script. Use the “chmod” (change mode) command for this purpose.

What is the error No 13 in Python?

In Python, If we provide a folder path instead of a file path while reading a file or if the Python does not have the required permission to perform file operations(open, read, write), you will encounter PermissionError: [Errno 13] Permission denied error.


2 Answers

IOError: [Errno 13] Permission denied: 'juliodantas2015.json'

tells you everything you need to know: though you successfully made your python program executable with your chmod, python can't open that juliodantas2015.json' file for writing. You probably don't have the rights to create new files in the folder you're currently in.

like image 168
Marcus Müller Avatar answered Oct 19 '22 20:10

Marcus Müller


I had a similar problem. I was attempting to have a file written every time a user visits a website.

The problem ended up being twofold.

1: the permissions were not set correctly

2: I attempted to use
f = open(r"newfile.txt","w+") (Wrong)

After changing the file to 777 (all users can read/write)
chmod 777 /var/www/path/to/file
and changing the path to an absolute path, my problem was solved
f = open(r"/var/www/path/to/file/newfile.txt","w+") (Right)

like image 34
Mo Jo Avatar answered Oct 19 '22 20:10

Mo Jo