dtmwnqng38644 2013-10-02 11:14
浏览 96

在Apache2上运行Python脚本时,我收到此错误:IOError:[Errno 13]权限被拒绝

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?

  • 写回答

2条回答 默认 最新

  • duanhuan7750 2013-10-03 12:01
    关注

    Thank you for the tips but it didn't help. I found a dirty way to solve the problem. While putting the files in /tmp/ folder I don't have the 'Permission denied' error anymore.

    评论

报告相同问题?

悬赏问题

  • ¥15 我的数据无法存进链表里
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端