[英]Which user opens a file in python?
I am working with django and celery. 我正在和django和芹菜一起工作。 In my celery task, I instantiate a class and that class is responsible for generating and mailing a CSV file.
在我的芹菜任务中,我实例化一个类,该类负责生成和邮寄CSV文件。 My problem is I am getting
IOError: [Errno 13] Permission denied
when i try to do fp = open(filename, 'w')
. 我的问题是我得到
IOError: [Errno 13] Permission denied
当我尝试做fp = open(filename, 'w')
时IOError: [Errno 13] Permission denied
。 But how do I get to know which user of my server is trying to create that file and how can I provide that user with appropriate permissions.I am working on AWS server. 但是,我如何才能知道我的服务器的哪个用户正在尝试创建该文件,以及如何为该用户提供适当的权限。我正在使用AWS服务器。 My code for writing files is this:
我编写文件的代码是这样的:
with open(filename, 'w') as f_pointer:
os.chmod(filename, 777)
myfile = csv.writer(f_pointer)
myfile.writerow(columns)
myfile.writerows(rows)
Thanks 谢谢
First check the file permission or owner , then use the property permission. 首先检查文件权限或所有者,然后使用属性权限。
ls -l filename ls -l filename
Another, you should check if this user can create the filename in the directory . 另外,您应该检查该用户是否可以在目录中创建文件名。
The file is opened by the same user who is running the process. 该文件由运行该进程的同一用户打开。 Now if the directory where you are creating the file or file you opening to write to are not writable by the user, then chmod will not work.
现在,如果用户无法写入您要创建要写入的文件或文件的目录,则chmod将不起作用。
You'll have to chose the directory/file that is writable by the user. 您必须选择用户可写的目录/文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.