so i'm attempting deploy python flask app ubuntu aws ec2 instance. i've setup mod_wsgi, configured virtual host setup virtualenv , created alias server static files. reason can't custom url api routes return correct information. i've tried i've searched everywhere last option.
#!/usr/bin/env python import threading import subprocess import uuid import json celery import celery celery.task import task celery.decorators import task celery.result import asyncresult scripts.runtable import runtable scripts.getcities import getcities scripts.pullscript import createoperation flask import flask, render_template, make_response, url_for, abort, jsonify, request, send_from_directory, response app = flask(__name__) app.config['celery_broker_url'] = 'amqp://guest:guest@localhost:5672//' app.config['celery_result_backend'] = 'amqp' app.config['celery_task_result_expires'] = 18000 app.config['celery_accept_content'] = ['json'] app.config['celery_task_serializer'] ='json' app.config['celery_result_serializer'] = 'json' operation = createoperation() cities = getcities() table = runtable() value = '' state = '' celery = celery(app.name, backend=app.config['celery_result_backend'], broker=app.config['celery_broker_url']) celery.conf.update(app.config) @task(bind=true) def pull_async_data(self, data): global state state = pull_async_data.request.id operation.runsequence(data) @app.route('/api/v1/getmapinfo', methods=['get']) def map(): mp = operation.getmapdata() resp = response(mp, status=200, mimetype="application/json") return resp @app.route('/api/v1/gettable', methods=['get']) def tables(): tb = table.gettableinfo() resp = response(tb, status=200, mimetype="application/json") return resp ##get states db @app.route('/api/v1/getstates', methods=['get']) def states(): st = cities.getstatesfromdb() resp = response(st, status=200, mimetype="application/json") return resp @app.route('/api/v1/getcities', methods=['post']) def city(): data = request.get_json() # print data ct = cities.getcitiesfromdb(data) resp = response(ct, status=200, mimetype="application/json") return resp @app.route('/api/v1/getqueue', methods=['get']) def queue(): queue = operation.getcurrentqueue() resp = response(queue, status=200, mimetype="application/json") return resp ##checking status of api progress @app.route('/api/v1/checkstatus', methods=['get']) def status(): res = pull_async_data.asyncresult(state).state js = json.dumps({'state': res}) resp = response(js, status=200, mimetype="application/json") return resp ##perform pull , start script @app.route('/api/v1/pull', methods=['post']) def generate(): global value value = json.dumps(request.get_json()) count = operation.getcurrentqueue(value) pull_async_data.apply_async(args=(value, )) js = json.dumps({"operation": "started", "totalqueue": count}) resp = response(js, status=200, mimetype="application/json") return resp ##check main app if __name__ == "__main__": app.run(debug=true)
here wsgi file oakapp.wsgi
#!/usr/bin/python import sys activate_this = '/var/www/oakapp/venv/bin/activate_this.py' execfile(activate_this, dict(__file__=activate_this)) sys.path.append('/var/www/oakapp') print sys.path.insert(0, '/var/www/oakapp/scripts') app import app application
here virtualhost environment
<virtualhost *:80> servername oakapp.com documentroot /var/www/oakapp alias /js /var/www/oakapp/js alias /css /var/www/oakapp/css wsgidaemonprocess oakapp user=apps group=ubuntu threads=5 wsgiscriptalias / /var/www/oakapp/oakapp.wsgi <directory /var/www/oakapp/> wsgiprocessgroup oakapp wsgiapplicationgroup %{global} wsgiscriptreloading on order allow,deny allow </directory> errorlog /var/www/oakapp/logs/oakapp_error.log loglevel info customlog /var/www/oakapp/logs/oakapp_access.log combined </virtualhost>
here access log, it's creating wsgi instance, have doing right.
[tue apr 28 04:30:03.705360 2015] [:info] [pid 2611:tid 140512828155776] mod_wsgi (pid=2611): attach interpreter ''. [tue apr 28 04:30:11.704865 2015] [:info] [pid 2611:tid 140512695293696] [remote 72.219.180.235:10929] mod_wsgi (pid=2611, process='oakapp', application=''): loading wsgi script '/var/www/oakapp/oakapp.wsgi'. [tue apr 28 04:30:11.705804 2015] [:error] [pid 2611:tid 140512695293696] none
here netstate -plunt output
active internet connections (only servers) proto recv-q send-q local address foreign address state pid/program name tcp 0 0 0.0.0.0:22 0.0.0.0:* listen 1062/sshd tcp 0 0 127.0.0.1:3031 0.0.0.0:* listen 29277/uwsgi tcp 0 0 0.0.0.0:46035 0.0.0.0:* listen 24222/beam tcp6 0 0 :::22 :::* listen 1062/sshd tcp6 0 0 :::5672 :::* listen 24222/beam tcp6 0 0 :::80 :::* listen 2608/apache2 tcp6 0 0 :::4369 :::* listen 24197/epmd udp 0 0 0.0.0.0:17372 0.0.0.0:* 568/dhclient udp 0 0 0.0.0.0:68 0.0.0.0:* 568/dhclient udp6 0 0 :::28264 :::* 568/dhclient
here directory structure
├── app.py ├── app.pyc ├── css │ ├── fonts │ │ ├── untitled-font-1.eot │ │ ├── untitled-font-1.svg │ │ ├── untitled-font-1.ttf │ │ └── untitled-font-1.woff │ ├── leaflet.css │ └── master.css ├── js │ ├── images │ │ ├── layers-2x.png │ │ ├── layers.png │ │ ├── marker-icon-2x.png │ │ ├── marker-icon.png │ │ └── marker-shadow.png │ ├── leaflet.js │ └── main.js ├── json │ └── states.json ├── logs │ ├── oakapp_access.log │ └── oakapp_error.log ├── oakapp.wsgi ├── sass │ └── master.scss ├── scripts │ ├── database │ │ ├── cities_extended.sql │ │ ├── oak.db │ │ └── states.sql │ ├── getcities.py │ ├── getcities.pyc │ ├── __init__.py │ ├── __init__.pyc │ ├── pullscript.py │ ├── pullscript.pyc │ ├── runtable.py │ └── runtable.pyc ├── templates └── index.html
any appreciated.
here curl request ran personal machine host machine
djove:.ssh djowinz$ curl http://**.*.**.139/api/v1/gettable <!doctype html public "-//w3c//dtd html 3.2 final//en"> <title>500 internal server error</title> <h1>internal server error</h1> <p>the server encountered internal error , unable complete request. either server overloaded or there error in application.</p>
here curl request ran host machine host machine using localhost requested.
root@ip-172-31-24-66:/var/www/oakapp# curl http://localhost/api/v1/gettable <!doctype html public "-//w3c//dtd html 3.2 final//en"> <title>500 internal server error</title> <h1>internal server error</h1> <p>the server encountered internal error , unable complete request. either server overloaded or there error in application.</p>
turns out issue how instantiating uwsgi. removed scratch , walked through flask installation instructions uwsgi , able work.