IOError: [Errno 13] Permission denied

后端 未结 3 2158
庸人自扰
庸人自扰 2020-12-19 01:10

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: \'         


        
3条回答
  •  醉话见心
    2020-12-19 01:58

    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)

提交回复
热议问题