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 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。