Franco
Franco

Reputation: 2926

Flask ImportError causing 500 error, works on local

Application works on local using python run.py but when deployed to Ubuntu VPS with Apache, it gives a 500 error.

Apache Logs return:

File "/var/www/ssapi/venv/lib/python2.7/site-packages/flask/app.py", line 28, in <module>, referer: http://api.soundshelter.net/
[Fri Jun 03 04:20:47.336788 2016] [:error] [pid 26915] [client 64.245.52.2:57465]     from .config import ConfigAttribute, Config, referer: http://api.soundshelter.net/
[Fri Jun 03 04:20:47.336819 2016] [:error] [pid 26915] [client 64.245.52.2:57465] ImportError: No module named config, referer: http://api.soundshelter.net/

Directory Structure

enter image description here

init.py

from flask import Flask
import config
from . import *

app = Flask(__name__)
app.config.from_object('config')

api.py

#!flask/bin/python
from flask import Flask, request, render_template, jsonify,abort, make_response

#http://flask.pocoo.org/snippets/9/
from werkzeug.contrib.cache import SimpleCache

import collections

#database connect
from flaskext.mysql import MySQL
import json
import sys


import sys, os
sys.path.append('/var/www/ssapi')
import config

reload(sys)
sys.setdefaultencoding('utf-8')

app = Flask(__name__)
app.config.from_object('config')

app.config['MYSQL_DATABASE_USER'] = config.user
app.config['MYSQL_DATABASE_PASSWORD'] = config.password
app.config['MYSQL_DATABASE_DB'] = config.database
app.config['MYSQL_DATABASE_HOST'] = config.host
....
....
....
if __name__ == '__main__':
app.run(debug=False,host='0.0.0.0')

I don't understand why it works on local but not deployed.

config.py definitely exists on VPS

enter image description here

Upvotes: 1

Views: 141

Answers (1)

Franco
Franco

Reputation: 2926

Re-install Flask fixed this. Thanks @cricket_007

Upvotes: 1

Related Questions