2013-10-02 80 views
0

我正在使用Python和PHP编写基于Web的应用程序。现在我在编程的同一台计算机上运行服务器。 Python脚本将在PHP中执行。这部分工作正常。在Apache2上运行Python脚本时,出现以下错误:IOError:[Errno 13] Permission denied

脚本必须读取文件并将路径名存储在列表中。该列表用于脚本的其余部分。

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'] 

函数readFiles将使用此列表。 fileList是一个全局变量。它由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!!\nUpload FIGFAMS-format only') #terminate program if incorrect file format is imported 
     FIGnumber = line[0:11] #remove '\n' 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 

当在Apache上运行时,我调用Python脚本,我得到的尾巴下面的错误-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' 

当我运行相同的脚本在IDLE和Linux终端中,该脚本不会给出错误以及文件内容的正确可视化。

我已经在脚本必须读取文件的目录中尝试了CHMOD 777,并使用ls -l检查这些文件是否具有所有权限。它是为我自己的帐户和Apache服务器的帐户完成的。我是这台Linux计算机的管理员。

在原始脚本中,fileList是在脚本本身中创建的。我还需要在IDLE中创建列表并复制/粘贴到在Apache上运行的相同脚本。没有这个在Apache []上只返回,并在IDLE中显示上面显示的正确列表。这可能是由相同的问题引起的,但在这种情况下没有错误消息。当我将正确的列表放在Apache上的脚本中时,发生错误。

为什么脚本在IDLE中直接在命令行中工作,在Apache上它没有打开文件的权限,即使CHMOD 777在我的帐户和服务器帐户上?

+1

你检查了父目录的权限吗?他们至少需要'x'权限 – Paco

+0

我的账户中CHMOD 777的含义是什么? –

+0

我的意思是我为我自己的用户帐户和Apache服务器在所需的文件夹和文件上使用的帐户将CHMOD设置为777。 –

回答

0

谢谢你的提示,但它没有帮助。我发现了一个肮脏的方法来解决这个问题。将文件放入/ tmp /文件夹时,我不再有'Permission denied'错误。

1

在我看来,在您的fileList变量中,在B.txt的路径中有Python模块之后有一个空格。

/home/mark/Bureaublad/Dropbox/Stage-documenten/Python-modules /Read_files_determine_overlap_and_visualisation/B.txt

试着移除它并检查一次。

相关问题