简体   繁体   中英

Which user opens a file in python?

I am working with django and celery. In my celery task, I instantiate a class and that class is responsible for generating and mailing a CSV file. My problem is I am getting IOError: [Errno 13] Permission denied when i try to do fp = open(filename, 'w') . 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. 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

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.

You'll have to chose the directory/file that is writable by the user.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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