Python – Apache: permission error while opening file

apache-2.2cgipython

I have a cgi script that opens a file (using python).

The cgi script runs fine but when I try to open this file, I get a permission error:

Traceback (most recent call last):   File "/asdf/pkgs/linux/intel/apache/2.2.14.rhas5.x86_64/htdocs/Sites/cgi-bin/avgsBarGraphView.py", line 304, in <module>
    main()   File "/asdf/pkgs/linux/intel/apache/2.2.14.rhas5.x86_64/htdocs/Sites/cgi-bin/avgsBarGraphView.py", line 61, in main
    f=open('/asdf/home/asdf/PYTHON/PERFRPTCRONJOB/TEST_FILES/testfile','r') PermissionError: [Errno 13] Permission denied: '/asdf/home/asdf/PYTHON/PERFRPTCRONJOB/TEST_FILES/testfile'

I've added the folder containing /asdf/home/asdf/PYTHON/PERFRPTCRONJOB/TEST_FILES/testfile to my httpd.conf.

<Directory "/asdf/home/asdf/PYTHON/PERFRPTCRONJOB/TEST_FILES/">
    AllowOverride None
    Options None
    Order allow,deny
    Allow from all
</Directory>

I've also changed the permissions of the folder TEST_FILES to 777 and the permissions of testfile to 777. I can open the file via python from the command line but when I try to open this file by running a cgi-script, it fails.

Best Answer

Check "x" permission for every (sub)directory in the path /asdf/home/asdf/PYTHON/PERFRPTCRONJOB/TEST_FILES/testfile

You can do this with the command:

ls -ld /asdf/home/asdf/PYTHON/PERFRPTCRONJOB/TEST_FILES/testfile /asdf/home/asdf/PYTHON/PERFRPTCRONJOB/TEST_FILES /asdf/home/asdf/PYTHON/PERFRPTCRONJOB /asdf/home/asdf/PYTHON /asdf/home/asdf /asdf/home /asdf