I am programming a web based application in Python and PHP. Now I running the server on the same computer as I am programming. The Python script will be executed in PHP. This part is working well.
The script have to read files and store pathnames in a list. This list is used in the rest ot the script.
fileList = ['/home/mark/Bureaublad/Dropbox/Stage-documenten/Python-modules /Read_files_determine_overlap_and_visualisation/B.txt', '/home/mark/Bureaublad/Dropbox/Stage-documenten/Python-modules/Read_files_determine_overlap_and_visualisation/D.txt', '/home/mark/Bureaublad/Dropbox/Stage-documenten/Python-modules/Read_files_determine_overlap_and_visualisation/C.txt', '/home/mark/Bureaublad/Dropbox/Stage-documenten/Python-modules/Read_files_determine_overlap_and_visualisation/E.txt', '/home/mark/Bureaublad/Dropbox/Stage-documenten/Python-modules/Read_files_determine_overlap_and_visualisation/A.txt']
The function readFiles will use this list. fileList is a global variable. Its made by glob.
def readFiles():
Dic = {}
for filePath in fileList:
geneList = [] #create a new list every new loop to put in genesPerBacteriaDic as value
for line in open(filePath, 'r').readlines(): #innerloop to read every file in lines
if not line.startswith('FIG'):
sys.exit('Wrong file format!!
Upload FIGFAMS-format only') #terminate program if incorrect file format is imported
FIGnumber = line[0:11] #remove '
' or another characters on the end of the string
geneList.append(FIGnumber)
head, fileName = os.path.split(filePath) # convert filePath to fileName
Dic[fileName] = geneList
return Dic
When running on Apache when I call the Python script I get the following error in tail -f /var/log/apache2/error.log :
Traceback (most recent call last):
File "/var/www/Coregrapher/makeVisualisation.py", line 192, in <module>
main()
File "/var/www/Coregrapher/makeVisualisation.py", line 48, in main
genesPerBacteriaDic = readFiles()
File "/var/www/Coregrapher/makeVisualisation.py", line 70, in readFiles
for line in open(filePath, 'r').readlines(): #innerloop to read every file in lines
IOError: [Errno 13] Permission denied: '/home/mark/Bureaublad/Dropbox/Stage-documenten/Python-modules/Readp_files_determine_overlap_and_visualisation/B.txt'
When I run the same script in IDLE and Linux Terminal the script gives no errors and the correct visualisation of the content of the file(s).
I tried already CHMOD 777 in the directory where the script have to read the files and check with ls -l the files have all permissions. It's done for my own account and the account of the Apache server. I am administrator on this Linux computer.
In the orignal script, fileList is created in the script itself. I also needed to create the list in IDLE and copy/paste to the same script thats running on Apache. Without this on Apache [] is returned only and in IDLE the correct list that is shown above. This may caused by the same problem but there is no error message in this case. When I put the correct list in the script on Apache, the error occured.
Why does the script work in IDLE and directly in command line correctly and on Apache it dont have the permission to open files, even with CHMOD 777 on my account and the account of the server?