title: Can't make Restplus Flask API run using uWSGI
body: <p>I'm working on a Flask API which works fine. I'm now trying to replace the Flask development server with uWSGI but everything breaks. I'm trying to solve this since 2 days, went through tutorials and searched here but couldn't find a solution to the problem. This is the code:
  <strong>app.py</strong></p>
  
  <pre><code>import logging.config
  
  import settings
  import utils
  from flask import Flask, Blueprint
  from flask_restplus import Resource, Api
  from flask_cors import CORS
  from api.restplus import api
  from api.gan.endpoints.client import ns as gan_client_namespace
  
  # create Flask application
  app = Flask(__name__)
  CORS(app) # needed for cross-domain requests, allow everything by default
  
  # load logging confoguration and create log object
  logging.config.fileConfig('logging.conf')
  log = logging.getLogger(__name__)
  
  # 
  @app.route("/")
  def hello():
      return "Hello World!"
  
  def __get_flask_server_params__():
      '''
      Returns connection parameters of the Flask application
  
      :return: Tripple of server name, server port and debug settings
      '''
      server_name = utils.get_env_var_setting('FLASK_SERVER_NAME', settings.DEFAULT_FLASK_SERVER_NAME)
      server_port = utils.get_env_var_setting('FLASK_SERVER_PORT', settings.DEFAULT_FLASK_SERVER_PORT)
  
      flask_debug = utils.get_env_var_setting('FLASK_DEBUG', settings.DEFAULT_FLASK_DEBUG)
      flask_debug = True if flask_debug == '1' else False
  
      return server_name, server_port, flask_debug
  
  def configure_app(flask_app, server_name, server_port):
      '''
      Configure Flask application
  
      :param flask_app: instance of Flask() class
      '''
      flask_app.config['SERVER_NAME'] = server_name + ':' + server_port
      flask_app.config['SWAGGER_UI_DOC_EXPANSION'] = settings.RESTPLUS_SWAGGER_UI_DOC_EXPANSION
      flask_app.config['RESTPLUS_VALIDATE'] = settings.RESTPLUS_VALIDATE
      flask_app.config['RESTPLUS_MASK_SWAGGER'] = settings.RESTPLUS_MASK_SWAGGER
      flask_app.config['ERROR_404_HELP'] = settings.RESTPLUS_ERROR_404_HELP
  
  def initialize_app(flask_app, server_name, server_port):
      '''
      Initialize Flask application with Flask-RestPlus
  
      :param flask_app: instance of Flask() class
      '''
      blueprint = Blueprint('tf_api', __name__, url_prefix='/tf_api')
  
      configure_app(flask_app, server_name, server_port)
      api.init_app(blueprint)
      api.add_namespace(gan_client_namespace)
  
      flask_app.register_blueprint(blueprint)
  
      #from werkzeug.contrib.fixers import ProxyFix
      #flask_app.wsgi_app = ProxyFix(flask_app.wsgi_app)
  
  def main():
      server_name, server_port, flask_debug = __get_flask_server_params__()
      initialize_app(app, server_name, server_port)
      log.info(
          '&gt;&gt;&gt;&gt;&gt; Starting TF Serving client at http://{}/ &gt;&gt;&gt;&gt;&gt;'.format(app.config['SERVER_NAME'])
          )
      app.run(debug=flask_debug, host=server_name)
  
  if __name__ == '__main__':
      main()
  </code></pre>
  
  <p>When I run this with <code>python app.py</code> it works fine. </p>
  
  <p><a href="https://i.stack.imgur.com/nw1IW.jpg" rel="nofollow noreferrer">Command Line Message</a></p>
  
  <p><a href="https://i.stack.imgur.com/sjXmo.jpg" rel="nofollow noreferrer">0.0.0.0:5001</a></p>
  
  <p><a href="https://i.stack.imgur.com/U16Vs.jpg" rel="nofollow noreferrer">0.0.0.0:5001/tf_api</a></p>
  
  <p>Now I'm just trying to get the same results using uWSGI:</p>
  
  <pre><code>uwsgi --http :8000 --wsgi-file app.py --callable app
  </code></pre>
  
  <p>The command line message looks fine:</p>
  
  <p><a href="https://i.stack.imgur.com/0ffxb.jpg" rel="nofollow noreferrer">Command Line Message</a></p>
  
  <p>Accessing 0.0.0.0:8000 also works</p>
  
  <p><a href="https://i.stack.imgur.com/nhqfn.jpg" rel="nofollow noreferrer">0.0.0.0:8000</a></p>
  
  <p>However, when I try to access the API it fails:
  <a href="https://i.stack.imgur.com/eIKF4.jpg" rel="nofollow noreferrer">0.0.0.0:8000/tf_api</a></p>
  
  <p>I've tried everything that came to my mind but didn't manage to solve this. Some of the things I did were:</p>
  
  <ol>
  <li><p>Include the following code:</p>
  
  <p>from werkzeug.contrib.fixers import ProxyFix
   flask_app.wsgi_app = ProxyFix(flask_app.wsgi_app)</p></li>
  <li><p>Remove <code>app.run()</code> (<a href="https://stackoverflow.com/questions/15156758/flask-gunicorn-app-cant-get-name-to-equal-main">Flask Gunicorn app can&#39;t get __name__ to equal &#39;__main__&#39;</a>)</p></li>
  <li><p>Move the function_calls outside the main function as otherwise they are only called when running app.py directly, similar to (<a href="https://stackoverflow.com/questions/23381947/flask-application-with-blueprintsuwsginginx-returning-404s-no-routing">Flask application with Blueprints+uWSGI+nginx returning 404&#39;s (no routing?)</a>)</p></li>
  </ol>
  
  <p>I really have no idea what else could be the issue. I found a similar problem but it's not applicable to my situation because it's related to NGINX which I'm not using yet (<a href="https://stackoverflow.com/questions/40684249/how-to-deploy-a-flask-restplus-app-with-nginx-uwgsi">How to deploy a flask-restplus app with nginx + uwgsi</a>). Any ideas what else I could try? Maybe I'm missing something obvious, didn't sleep much because of this.</p>