gis
gis

Reputation: 21

Unable to host flask application on IIS using httpPlatformHandler

I am trying to host a simple python application which uses flask library on IIS. Based on following link : https://learn.microsoft.com/en-us/visualstudio/python/configure-web-apps-for-iis-windows?view=vs-2022 am using httpPlatformHandler to host the application however, I get the following error as shown in screenshot.

enter image description here

Here is the python code

from flask import Flask
 
 def create_app():
     app = Flask(__name__)
 
     @app.route("/")
     def hello_world():
         return "<p>Hello, World!</p>"

Here is the webconfig file

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <handlers>
            <add name="httpPlatformHandler" path="*" verb="*" modules="httpPlatformHandler" resourceType="Unspecified" requireAccess="Script" />
        </handlers>
        <httpPlatform stdoutLogEnabled="true" stdoutLogFile=".\python.log" startupTimeLimit="20" processPath="C:\Users\<username>\AppData\Local\Programs\Python\Python312\python.exe" arguments="-m flask run --port %HTTP_PLATFORM_PORT%">
        </httpPlatform>
    </system.webServer>
</configuration>

I also made sure to give permission to IIS_IUSRS to Python folder as well as application folder.

I have not made any changes in IIS as I am not sure if any change is needed. I am doing it for the first time so quite possible that am missing something simple.

Upvotes: 0

Views: 231

Answers (1)

Jason Pan
Jason Pan

Reputation: 21916

Have you installed httpPlatformHandler ? If not, you can download it from here(httpplatformhandler).

And Here is a good blogs Written by Lex Li (MS Expert).

Running Flask Web Apps on IIS with HttpPlatformHandler

Test Result

enter image description here

Tips

If we facing some unexpected behavior, we also can try to grant permission like below.

enter image description here

Upvotes: 0

Related Questions