bind python/flask module app yo WINDOWS Server IIS

Stack Overflow Asked by Shaul.Sondak on January 1, 2022

I’m a novice python developer with very basic knowledge of this platform. We received a python app developed on Mac/Linux from a 3rd parry (consultant company), and I’m having trouble bind it to IIS on a WINDOWS WEB server.


  • Python 3.8.1, deploying flask and dash
  • Windows server 2012R2
  • IIS 8.5


  • FastCgi setting on IIS :
    enter image description here

  • Create a site under IIS (port 8051 in my test) and set the physical path to the folder where the and web.config files reside.
    enter image description here

enter image description here

  • The rest of the configuration is administrated by a web.config file at the app’s root folder.

Successful Simple Test

  • I successfully implemented a simple test file as follow:

                from flask import Flask
            app = Flask(__name__)

            from datetime import datetime 
            from urllib.parse import urlparse
            from flask import request
            import socket

            app.debug = True

            def kuki():    
                return "Hello from flask over IIS. host:[{}],  url:[{}],  TS:[{}]".format(socket.gethostname(), request.base_url,

            if __name__ == '__main__':


<?xml version="1.0" encoding="utf-8"?>
            <remove name="PythonHandler" />
        <add key="PYTHONPATH" value="D:_MyPythonHelloFlask" />
        <add key="WSGI_HANDLER" value="" />
        <add key="WSGI_LOG" value="D:_MyPythonHelloFlasklogHelloFlask.log" />

Problem running the full python app

  • An application folder reside under the app’s root folder
    enter image description here
    enter image description here

  • The py -m application command is successfully launching the service

  • Can someone advice how to set the web.config file to enable successful IIS binding?



One Answer

# Import Application level packages
import dash_html_components as html
import dash_bootstrap_components as dbc

# Import other neccessary classes, objects in project
from app import dash_app
from xxx import XXX

# Import Application dependent packages
import random
from datetime import date

# Set the app's HTML title
dash_app.title = "**** *****"

# Set the app's overall layout. 
# Each Content Element is imported by reference and 
# elements in each container will change dynamically (when respective callback is fired) as user enters inputs.
dash_app.layout = html.Div(


# Start flask server
flask_app = dash_app.server

# Run application
def run():

    # open webbrowser automatically:
    if Config.AUTOOPEN:
        import threading, webbrowser
        url = f"http://{Config.HOST}:{Config.PORT}"
        # Wait for 2.25 seconds initially for dash to process the app initially
        threading.Timer(2.25, lambda:

    # Add debug=Config.DEBUG as a parameter in order to debug in front-end
    dash_app.run_server(host=Config.HOST, port=Config.PORT)

# Import OS level packages
import os

# Import Application level packages
from flask import send_from_directory
import dash
import dash_bootstrap_components as dbc

# Pull in bootstrap darkly stylesheet
external_stylesheets = [

# Create instance of dash app
dash_app = dash.Dash(__name__, external_stylesheets=external_stylesheets, url_base_pathname=Config.URL_BASE_PATH)

# Create instance of dash server
server = dash_app.server

Created a new :

import app

from index import flask_app

from index import run

if __name__ == "__main__":
    # Main entry point for app


<?xml version="1.0" encoding="utf-8"?>
            <remove name="PythonHandler"/>
            <add name="PythonHandler" path="*" verb="*" modules="FastCgiModule" scriptProcessor="c:python3_8_1python.exe|"
                resourceType="Unspecified" requireAccess="Script"/>
        <add key="PYTHONPATH" value="D:_MyPythonTCO_WIP2TCO"/>
        <add key="WSGI_HANDLER" value="entry_point.flask_app"/>
        <add key="WSGI_LOG" value="D:_MyPythonTCO_WIP2TCOLogTCO_WIP2.log"/>



Answered by Shaul.Sondak on January 1, 2022

Add your own answers!

Ask a Question

Get help from others!

© 2024 All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP