Apache上的Flask:FileNotFoundError:[Errno 2]没有这样的文件或目录

2024-05-23 21:21:48 发布

您现在位置:Python中文网/ 问答频道 /正文

我在一个远程服务器上的apache上部署了my Flask应用程序,但是在调用load\u transcript()函数时,我得到了一个FileNotFoundError。但是,在调用download_sound_file()函数时,我没有收到此错误。这两个功能在我的本地部署上都能很好地工作。我在下面提供了我的目录结构。有人能提供一些关于如何调试这个的建议吗?在

这是中的相关代码应用程序副本公司名称:

def readFile(filename):
    fileSegments = []
    with open(filename, 'r') as csvfile:
        spamreader = csv.reader(csvfile, delimiter='\t', quotechar='|')
        for row in spamreader:
            outputDict = {}
            outputDict["id"] = row[0]
            outputDict["speakerID"] = row[1]
            outputDict["text"] = row[2]
            fileSegments.append(outputDict)
    return fileSegments

@app.route('/transcript/<meetingid>')
def load_transcript(meetingid):
    template_variables = {}
    template_variables["segments"] = readFile("transcripts/"+meetingid+".txt")
    return render_template('annotator.html', data=template_variables)

@app.route('/music/<meetingid>')
def download_sound_file(meetingid):
    return send_file('audio/'+meetingid+'/'+meetingid+".wav")

以下是我的目录结构:

^{pr2}$

在应用程序.wsgi公司名称:

activate_this = '/home/ubuntu/meeting_data_parser/annotator/env2/bin/activate_this.py'
with open(activate_this) as f:
    exec(f.read(), dict(__file__=activate_this))

import sys
import logging

logging.basicConfig(stream=sys.stderr)
sys.path.insert(0,"/var/www/html/annotator")

from app import app as application

Apache配置:

<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/html

    WSGIDaemonProcess annotator threads=5
    WSGIScriptAlias / /var/www/html/annotator/app.wsgi

    <Directory flaskproject>
        WSGIProcessGroup annotator
        WSGIApplicationGroup %{GLOBAL}
        Order deny,allow
        Allow from all
    </Directory>    


    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

</VirtualHost>

以下是错误的堆栈跟踪:

[Tue Jun 12 12:47:48.437405 2018] [wsgi:error] [pid 32518:tid 140647948343040] Traceback (most recent call last):
[Tue Jun 12 12:47:48.437409 2018] [wsgi:error] [pid 32518:tid 140647948343040]   File "/home/ubuntu/meeting_data_parser/annotator/env2/lib/python3.5/site-packages/flask/app.py", line 2292, in wsgi_app
[Tue Jun 12 12:47:48.437412 2018] [wsgi:error] [pid 32518:tid 140647948343040]     response = self.full_dispatch_request()
[Tue Jun 12 12:47:48.437415 2018] [wsgi:error] [pid 32518:tid 140647948343040]   File "/home/ubuntu/meeting_data_parser/annotator/env2/lib/python3.5/site-packages/flask/app.py", line 1815, in full_dispatch_request
[Tue Jun 12 12:47:48.437418 2018] [wsgi:error] [pid 32518:tid 140647948343040]     rv = self.handle_user_exception(e)
[Tue Jun 12 12:47:48.437421 2018] [wsgi:error] [pid 32518:tid 140647948343040]   File "/home/ubuntu/meeting_data_parser/annotator/env2/lib/python3.5/site-packages/flask/app.py", line 1718, in handle_user_exception
[Tue Jun 12 12:47:48.437424 2018] [wsgi:error] [pid 32518:tid 140647948343040]     reraise(exc_type, exc_value, tb)
[Tue Jun 12 12:47:48.437426 2018] [wsgi:error] [pid 32518:tid 140647948343040]   File "/home/ubuntu/meeting_data_parser/annotator/env2/lib/python3.5/site-packages/flask/_compat.py", line 35, in reraise
[Tue Jun 12 12:47:48.437429 2018] [wsgi:error] [pid 32518:tid 140647948343040]     raise value
[Tue Jun 12 12:47:48.437431 2018] [wsgi:error] [pid 32518:tid 140647948343040]   File "/home/ubuntu/meeting_data_parser/annotator/env2/lib/python3.5/site-packages/flask/app.py", line 1813, in full_dispatch_request
[Tue Jun 12 12:47:48.437434 2018] [wsgi:error] [pid 32518:tid 140647948343040]     rv = self.dispatch_request()
[Tue Jun 12 12:47:48.437436 2018] [wsgi:error] [pid 32518:tid 140647948343040]   File "/home/ubuntu/meeting_data_parser/annotator/env2/lib/python3.5/site-packages/flask/app.py", line 1799, in dispatch_request
[Tue Jun 12 12:47:48.437439 2018] [wsgi:error] [pid 32518:tid 140647948343040]     return self.view_functions[rule.endpoint](**req.view_args)
[Tue Jun 12 12:47:48.437441 2018] [wsgi:error] [pid 32518:tid 140647948343040]   File "/var/www/html/annotator/app.py", line 46, in load_annotation
[Tue Jun 12 12:47:48.437446 2018] [wsgi:error] [pid 32518:tid 140647948343040]     template_variables["segments"] = readFile("transcripts/"+meetingid+".txt")
[Tue Jun 12 12:47:48.437460 2018] [wsgi:error] [pid 32518:tid 140647948343040]   File "/var/www/html/annotator/app.py", line 11, in readFile
[Tue Jun 12 12:47:48.437463 2018] [wsgi:error] [pid 32518:tid 140647948343040]     with open(filename, 'r') as csvfile:
[Tue Jun 12 12:47:48.437467 2018] [wsgi:error] [pid 32518:tid 140647948343040] FileNotFoundError: [Errno 2] No such file or directory: 'transcripts/Bdb001.txt'

Tags: inpyappwsgihomedatalineerror