php - 在 Apache2 上运行 Python 脚本时,出现此错误 : IOError: [Errno 13] Permission denied

标签 php python linux apache

我正在使用 Python 和 PHP 编写基于 Web 的应用程序。现在我在编程时在同一台计算机上运行服务器。 Python 脚本将在 PHP 中执行。这部分工作正常。

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

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 脚本时,我在 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'

当我在 IDLE 和 Linux Terminal 中运行相同的脚本时,脚本没有给出错误并且文件内容的正确可视化。

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

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

为什么脚本在 IDLE 和直接在命令行中正确运行,而在 Apache 上它没有打开文件的权限,即使在我的帐户和服务器帐户上使用 CHMOD 777 也是如此?

最佳答案

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

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

尝试将其删除并检查一次。

关于php - 在 Apache2 上运行 Python 脚本时,出现此错误 : IOError: [Errno 13] Permission denied,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19135635/

相关文章:

php - 如何用 PHP 解密 iPhone 加密的 AES256 文本

python - 用于从组中删除用户的 Perl 或 Python 脚本

python - 安装 tensorflow 1.4

regex - 将引号字符串中的换行符替换为\n

php - 通过 SESSION 链接用户

php - php get函数有问题吗?

python - _really_ 禁用 GtkTreeView 搜索

android - 连接时自动启动 MTK 设备(非三星)

c - 使用 poll() 检查文件修改

php - 转换为 sprintf() 查询