IOError: [Errno 13] Permission denied

后端 未结 3 2127
庸人自扰
庸人自扰 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)

    0 讨论(0)
  • 2020-12-19 02:02

    I have a really stupid use case for why I got this error. Originally I was printing my data > file.txt

    Then I changed my mind, and decided to use open("file.txt", "w") instead. But when I called python, I left > file.txt .....

    0 讨论(0)
  • 2020-12-19 02:17
    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.

    0 讨论(0)
提交回复
热议问题