2013-10-02 98 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

試着移除它並檢查一次。

相關問題