我在远程服务器上的apache上部署了我的Flask应用程序,但是当调用load_transcript()函数时,我得到了一个FileNotFoundError。但是,调用download_sound_file()函数时,我不会收到此错误。这两个功能在我的本地部署中完美运行。我在下面提供了我的目录结构。有人可以提供一些有关如何调试的建议吗?
以下是app.py中的相关代码:
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")
这是我的目录结构:
.
├── app.py
├── app.wsgi
├── _templates
| ├── annotator.html
| └── ...
├── transcripts
| ├── Bdb001.txt
| └── ...
├── audio
| ├── Bdb001
| | ├── Bdb001.wav
| | ├── Bdb001.mp3
| | └── ...
| └── ...
app.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'