简体   繁体   English

哪个用户在python中打开文件?

[英]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.

相关问题 在Python中以哪种编码打开utf-8 csv文件,该文件在带有Windows的Excel(ANSI)中正确打开 - Which encoding to open utf-8 csv file in Python which opens correctly in Excel with Windows (ANSI) Python文件打开并立即关闭 - Python file opens and immediately closes 文件资源管理器在 Tkinter Python 程序中自动打开 - File explorer automatically opens in Tkinter Python program 当 PyCharm 打开时运行 python 文件 - Run python file when PyCharm opens shell 脚本,它使用 python 脚本的参数打开 python - shell script which opens python with arguments to python script Python 处理打开另一个工具的 cmd 命令 - Python process a cmd command which opens another tool 打开新 Tk() window 的按钮在 Python Tkinter 中单击它 - Button which opens a new Tk() window on clicking it in Python Tkinter 如何导入一个模块,该模块在与模块相同的目录中打开文件? - How to import a module which opens a file in the same directory as the module? Python:用户输入要写入/写入的文件名。 程序然后打开/读取 - Python: User inputs filename to write/be written to. program then opens/reads webbrowser 用户数据目录打开不同的浏览器环境(python selenium) - webbrowser user data dir opens different browser environment (python selenium )
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM