2

I am facing a wsgi exception while running my flask application code in the server.

Here is my manage.py

from app import app1, db
from flask_script import Manager, Shell

from flask_migrate import Migrate, MigrateCommand
migrate = Migrate(app1, db)

manager = Manager(app1)
manager.add_command('db', MigrateCommand)


def make_shell_context():
    return dict(app=app1, db=db)

manager.add_command("shell", Shell(make_context=make_shell_context))

if __name__ == '__main__':

    manager.run()

and app.py

app1 = Flask(__name__)
app1.config.from_object(config['default'])

rest_api = Api(app1)

db = SQLAlchemy(app1)

bcrypt = Bcrypt(app1)

from app import routes

Compress(app1)
assets = Environment(app1)
define_assets(assets)
cache = Cache(app1,config={'CACHE_TYPE': 'simple'})

In my local, there is no error. I run my application with this python manage.py runserver command.

Now, In the server I successfully done this steps python manage.py db init, python manage.py db migrate, python manage.py db upgrade and it created, updated Database successfully. I have installed passenger to serve the application.

My passenger_wsgi.py looks like this

from manage import  manager as application

Now, when I run passenger start --port 3003 -a '0.0.0.0', It throws me this error

[ 2016-08-16 07:44:15.0758 30180/7f90226f8700 age/Cor/Con/InternalUtils.cpp:112 ]: [Client 2-1] Sending 502 response: application did not send a complete response
App 30251 stderr: Traceback (most recent call last):
App 30251 stderr:   File "/usr/share/passenger/helper-scripts/wsgi-loader.py", line 163, in main_loop
App 30251 stderr:     socket_hijacked = self.process_request(env, input_stream, client)
App 30251 stderr:   File "/usr/share/passenger/helper-scripts/wsgi-loader.py", line 297, in process_request
App 30251 stderr:     result = self.app(env, start_response)
App 30251 stderr: TypeError: __call__() takes at most 2 arguments (3 given)
pd farhad
  • 6,352
  • 2
  • 28
  • 47
  • 4
    `manager` isn't your application `app1` is in `app.py`. The manger is just used to manage it in you dev environment. – Joe Doherty Aug 16 '16 at 12:16

1 Answers1

3

Import the Flask application as the application to run, not the Flask-Script manager.

from app import app1 as application

A Flask-Script manager is for running commands on the command line. It is not a WSGI application. You can still use it to run other commands, but the WSGI server needs the Flask application.

davidism
  • 121,510
  • 29
  • 395
  • 339