结果:内部服务器错误
注意:
这是我的应用程序主模块:
名称:api.py
from flask import Flask, request, jsonify, render_template
import joblib
app = Flask(__name__)
classifier = joblib.load('./model/pipeline.pkl')
@app.route('/')
def home():
message = "API has been deployed correctly!"
return render_template('index.html', message=message)
@app.route('/predict', methods=['POST'])
def predict():
json_ = request.json
prediction = classifier.predict(json_['text']).tolist()
return jsonify({'prediction': prediction[0] })
if __name__ == '__main__':
classifier = joblib.load('./model/pipeline.pkl')
app.run(host='0.0.0.0')
这是我的 wsgi 文件:
from api import app
if __name__ == "__main__":
app.run()
这是我的ini文件:
[uwsgi]
plugins = python3
master = true
protocol = uwsgi
socket = 127.0.0.1:8090
chdir = /home/username/htdocs/api.domain.com
wsgi-file = /home/username/htdocs/api.domain.com/api/wsgi.py
callable = app
# In case you're using virtualenv uncomment this:
virtualenv = /home/username/htdocs/api.domain.com/env
# Needed for OAuth/OpenID
buffer-size = 8192
# Reload when consuming too much of memory
reload-on-rss = 250
# Increase number of workers for heavily loaded sites
workers = 4
# Enable threads for Sentry error submission
enable-threads = true
# Child processes do not need file descriptors
close-on-exec = true
# Avoid default 0000 umask
umask = 0022
#Run as weblate user
uid = username
gid = username
# Enable harakiri mode (kill requests after some time)
# harakiri = 3600
# harakiri-verbose = true
# Enable uWSGI stats server
# stats = :1717
# stats-http = true
# Do not log some errors caused by client disconnects
ignore-sigpipe = true
ignore-write-errors = true
disable-write-exception = true
这是我的虚拟主机文件:
server {
listen 80;
listen [::]:80;
listen 443 ssl http2;
listen [::]:443 ssl http2;
{{ssl_certificate_key}}
{{ssl_certificate}}
server_name api.domain.com;
{{root}}
{{nginx_access_log}}
{{nginx_error_log}}
if ($scheme != "https") {
rewrite ^ https://$host$uri permanent;
}
location ~ /.well-known {
auth_basic off;
allow all;
}
{{settings}}
index index.html;
location / {
include uwsgi_params;
uwsgi_read_timeout 3600;
#uwsgi_pass unix:///run/uwsgi/app/weblate/socket;
uwsgi_pass 127.0.0.1:8090;
}
#location ~* ^.+\.(css|js|jpg|jpeg|gif|png|ico|gz|svg|svgz|ttf|otf|woff|woff2|eot|mp4|ogg|ogv|webm|webp|zip|swf)$ {
# add_header Access-Control-Allow-Origin "*";
# expires max;
# access_log on;
#}
if (-f $request_filename) {
break;
}
}
我正在使用 oracle 云,在部署 flask 应用程序时遇到同样的问题,它总是给我 500 或 502 错误,我发现许多其他问题,例如使用 ftp 与 couldpanel.io 连接,可能存在一些错误:/