简体   繁体   中英

“Permission denied” error when using “fopen” function in Python

I have the following code, and I run it from localhost:

def create_names_file(req, names, data, profileid):
    s = names
    fname = str(profileid)
    fpath = req.conf["inf_path"]+"/"+fname
    f = open(fpath, 'w')

req.conf["inf_path"] is /opt/fp/trunk/analysis/2/ , and I receive permission error.I use Ubuntu OS. How can I solve this problem?

You seem to be trying to open a file named /opt/fp/trunk/analysis/2/ which in invalid due to the trailing slash. Possibly that is a typo so, if the required file already exists, who owns it?

Does the user that you run Python as have permissions to write to that file?

Check the permissions reported by ls -l /opt/fp/trunk/analysis/2 .

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