简体   繁体   中英

Numpy - Internal Server Error on Apache

I have created a Flask app on EC2 (Ubuntu) so I can use a predictive model I have created to send two data points to from another system. Everything works fine without numpy, but as soon as I add it back in Apache throws an internal server error. All modules have been installed and verified with pip --freeze. The app lives in a directory named flaskapp.

Here is the code from my wsgi:

import sys

sys.path.insert(0, '/var/www/html/flaskapp')
from flaskapp import app as application

Here are the changes Ive made to the Apache conf file:

WSGIDaemonProcess flaskapp threads=5
WSGIScriptAlias / /var/www/html/flaskapp/flaskapp.wsgi

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

and here is the Flask app code:

#imports
import numpy as np
from flask import Flask, jsonify, request
import pickle as pickle

#Open Predicitve Model
pklmodel = 'model.pkl'
my_model = pickle.dumps(pklmodel, protocol=2)
app = Flask(__name__)

#Flask App Endpoint
@app.route('/api',methods=['POST'])

#Predicitions Function
def make_predict():
    data = request.get_json(force=True)
    predict_request = [data['Temp'],data['Pressure']]
    predict_request = np.array(predict_request)
    predGhi = my_model.predict(predict_request)
    output = [predGhi[0]]
    return jsonify(results=output)

#run app as webservice
if __name__ == '__main__':
   app.run()

What am I missing?

If it's an Internal Server Error, there should be a record in Apache's error log. Most probably, there's an uncaught exception and there'll be its stacktrace there. See Debugging Techniques — mod_wsgi 4.5.16 documentation .

When using mod_wsgi, unless you or the web framework you are using takes specific action to catch exceptions and present the details in an alternate manner, the only place that details of uncaught exceptions will be recorded is in the Apache error log files. The Apache error log files are therefore your prime source of information when things go wrong.

A mod_wsgi error log entry on a user request looks something like this :

[error] [client ..] mod_wsgi (pid=8184): Exception occurred processing WSGI script '.../django.wsgi'.
[error] [client ..] Traceback (most recent call last):
<...>
[error] [client ..] File "../apps/py26_logging/handlers.py", line 394, in emit
[error] [client ..]   self.stream.flush()
[error] [client ..] ValueError: I/O operation on closed file

If it's without [client] , this means the error occurred on loading/unloading the module (eg a compilation error).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM