简体   繁体   English

IOError:[Errno 13] 权限被拒绝

[英]IOError: [Errno 13] Permission denied

I have this piece of code to create a .json file to store python data.我有这段代码来创建一个 .json 文件来存储 python 数据。 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: Python代码:

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.在命令行中我输入了 chmod 777 *.py但仍然无法正常工作。 How can i fix this ?我怎样才能解决这个问题 ?

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 1:权限设置不正确

2: I attempted to use 2:我尝试使用
f = open(r"newfile.txt","w+") (Wrong) f = open(r"newfile.txt","w+") (错误)

After changing the file to 777 (all users can read/write)将文件更改为 777 后(所有用户都可以读/写)
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) f = open(r"/var/www/path/to/file/newfile.txt","w+") (右)

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.告诉你你需要知道的一切:尽管你成功地用你的chmod使你的 python 程序可执行,python 无法打开那个juliodantas2015.json'文件进行编写。 You probably don't have the rights to create new files in the folder you're currently in.您可能无权在当前所在的文件夹中创建新文件。

I have a really stupid use case for why I got this error.我有一个非常愚蠢的用例来解释为什么会出现这个错误。 Originally I was printing my data > file.txt最初我正在打印我的数据 > file.txt

Then I changed my mind, and decided to use open("file.txt", "w") instead.然后我改变了主意,决定改用 open("file.txt", "w") 。 But when I called python, I left > file.txt .....但是当我调用 python 时,我离开了 > file.txt .....

I faced same issue this morning when I tried to write data to opened excel file note that you can not edit a file when it's open .今天早上,当我尝试将数据写入打开的 excel 文件时,我遇到了同样的问题,请注意,当文件打开时,您无法编辑文件。 Please close the file and then it work normally请关闭文件,然后它才能正常工作

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM