简体   繁体   English

在Apache2上运行Python脚本时,出现以下错误:IOError:[Errno 13]权限被拒绝

[英]While running a Python script on Apache2, I get this error: IOError: [Errno 13] Permission denied

I am programming a web based application in Python and PHP. 我正在用Python和PHP编写一个基于Web的应用程序。 Now I running the server on the same computer as I am programming. 现在,我在编程时在同一台计算机上运行服务器。 The Python script will be executed in PHP. Python脚本将在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. 函数readFiles将使用此列表。 fileList is a global variable. fileList是全局变量。 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!!\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

When running on Apache when I call the Python script I get the following error in tail -f /var/log/apache2/error.log : 当我在Python上调用Python脚本时在Apache上运行时,在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). 当我在IDLE和Linux Terminal中运行相同的脚本时,该脚本不会显示任何错误,并且可以正确显示文件内容。

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. 我已经在脚本必须读取文件的目录中尝试过CHMOD 777,并使用ls -l检查文件是否具有所有权限。 It's done for my own account and the account of the Apache server. 这是针对我自己的帐户和Apache服务器的帐户完成的。 I am administrator on this Linux computer. 我是这台Linux计算机的管理员。

In the orignal script, fileList is created in the script itself. 在原始脚本中,fileList是在脚本本身中创建的。 I also needed to create the list in IDLE and copy/paste to the same script thats running on Apache. 我还需要在IDLE中创建列表,然后将其复制/粘贴到Apache上运行的相同脚本中。 Without this on Apache [] is returned only and in IDLE the correct list that is shown above. 如果没有此选项,则仅返回Apache [],并且在IDLE中返回上面显示的正确列表。 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. 当我在Apache的脚本中放入正确的列表时,发生了错误。

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? 为什么该脚本可以在IDLE中直接在命令行中正常工作,而在Apache上却没有打开文件的权限,即使在我的帐户和服务器帐户上使用CHMOD 777时也是如此?

It seems to me that in your fileList variable there is a space after Python-modules in the path of B.txt. 在我看来,在您的fileList变量中,B.txt路径中的Python模块后面有一个空格。

/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/B.txt

Try to remove it and check once. 尝试将其删除并检查一次。

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. 将文件放在/ tmp /文件夹中时,我不再遇到“权限被拒绝”错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 403 - Ubuntu 14.04上的权限被拒绝错误 - apache2 - 403 - Permission denied error on Ubuntu 14.04 - apache2 FPM 与 apache2 不工作(权限被拒绝) - FPM with apache2 not working (Permission denied) Apache2 / Debian 9 上的写入权限被拒绝 - Write permission denied on Apache2 / Debian 9 apache2无法访问目录-权限被拒绝 - apache2 cannot access directory - permission denied OSError:[Errno 13]使用Sublime phpcs软件包OSX 10.7时,python的权限被拒绝 - OSError: [Errno 13] Permission denied from python when using Sublime phpcs package, OSX 10.7 phpmyadmin错误13权限被拒绝 - phpmyadmin error 13 permission denied 在 php 脚本中使用 shell_exec() 运行 python 脚本会导致权限被拒绝错误 - Running python script with shell_exec() in php script results in permission denied error 请求库:无法建立新连接:[Errno 13] 权限被拒绝 - requests library: Failed to establish a new connection: [Errno 13] Permission denied 为什么它在运行Shell脚本时拒绝授予权限? - Why it is giving permission denied while running a shell script? SQLSTATE [HY000]:常规错误:13无法获取“ ./pics”的统计信息(错误代码:13-权限被拒绝) - SQLSTATE[HY000]: General error: 13 Can't get stat of './pics' (Errcode: 13 - Permission denied)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM