title: Gunicorn won't start Flask app because "Application object must be callable"
body: <p>This is maybe a Python noob question, but after having spent a whole day searching, I couldn't find a solution.</p>
  
  <p>I created a simple Flask application, here is an extract of the python_pgfutter_importer/app.py:</p>
  
  <pre><code>import os
  
  from flask import Flask, Blueprint
  
  from python_pgfutter_importer import settings
  from python_pgfutter_importer.api.importer.business import import_csv
  from python_pgfutter_importer.api.importer.endpoints.csv import ns as csv_importer_namespace
  from python_pgfutter_importer.api.restplus import api
  
  app = Flask(__name__)
  
  
  def initialize_app(flask_app):
      blueprint = Blueprint('api', __name__, url_prefix='/api')
      api.init_app(blueprint)
      api.add_namespace(csv_importer_namespace)
      flask_app.register_blueprint(blueprint)
  
  
  def main():
      initialize_app(app)
      app.run(debug=settings.FLASK_DEBUG, use_reloader=settings.FLASK_USE_RELOADER)
  
  
  if __name__ == "__main__":
      main()
  </code></pre>
  
  <p>Application is working well, I start it using this command:</p>
  
  <pre><code>python python_pgfutter_importer/app.py
  </code></pre>
  
  <p>Now I must host this application on a server, thus I have to use WSGI. Using all the tutorials I could find, I wrote this WSGI entry point (wsgi.py):</p>
  
  <pre><code>from python_pgfutter_importer import app as application
  
  if __name__ == "__main__":
      application.main()
  </code></pre>
  
  <p>When starting Gunicorn, here is the CLI output:</p>
  
  <pre><code>$gunicorn -b 127.0.0.1:8000 wsgi:application               
  [2018-11-12 09:15:48 +0100] [11782] [INFO] Starting gunicorn 19.9.0
  [2018-11-12 09:15:48 +0100] [11782] [INFO] Listening at: http://127.0.0.1:8000 (11782)
  [2018-11-12 09:15:48 +0100] [11782] [INFO] Using worker: sync
  [2018-11-12 09:15:48 +0100] [11785] [INFO] Booting worker with pid: 11785
  Application object must be callable.
  [2018-11-12 09:15:48 +0100] [11782] [INFO] Shutting down: Master
  [2018-11-12 09:15:48 +0100] [11782] [INFO] Reason: App failed to load.
  </code></pre>
  
  <p>It seems the problem is: <strong>Application object must be callable.</strong></p>
  
  <p>That doesn't make any sense, since the application is Flask and is of course callable.</p>
  
  <p>What can I be missing?</p>
  
  <p>Thanks</p>