How to run Python scripts on IIS 10 in Windows 11

I am learning Python, so I am teaching myself with very simple Python scripts, or at least trying to do so.

While my Python scripts run just fine via command-line, I would like to implement them on my IIS web server and view them as a web page. I have set it up so that I have a FastCGI module pointing to C:\Python313\python.exe %s %s and I also have downloaded and installed wfastcgi and point to that in the FastCGI handler mapping for all *.py files

helloworld.py:

print('Content-Type: text/plain')
print('')
print('Hello, world!')ode here

Going to http://localhost/cma/helloworld.py produces this:

HTTP Error 500.0 - Internal Server Error

scriptProcessor could not be found in application configuration

I don’t know what else to make these scripts work in IIS. What else do I need to do?

Thanks

It looks like you’ve tried to follow a StackOverflow answer (“Python on IIS: how?”), except it doesn’t even mention wfastcgi - which, however, is mentioned in another answer in that very thread. As per the documentation, the wfastcgi itself requires an explicit handler, such as -

<appSettings>
    <!-- Required settings -->
    <add key="WSGI_HANDLER" value="my_app.wsgi_app()" />
    <add key="PYTHONPATH" value="C:\MyApp" />

    <!-- Optional settings ... -->
  </appSettings>

- which is nowhere to be found in your own helloworld.py.

I’m not by no means an expert on IIS/FastCGI myself, yet perhaps it might make a bit more sense to find and stick to just one approach/tutorial for this - from start to finish?

I wound up going to several different sources to try to figure this out, all to no avail. Nothing I found online works for me.

Latest I did was to put a web.config in my C:\inetpub\wwwroot\cma folder where the HTML and Python scripts are and tried that way. I now get a 500.19 Internal Server Error with its inability to find web.config

Here is my web.config:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.webServer>
    <handlers>
      <add name="FastCGI" 
      path="*" 
      verb="*" 
      modules="FastCgiModule" 
      scriptProcessor="C:\Python313\python.exe|C:\Python313\Lib\site-packages\wfastcgi.exe" 
      resourceType="Unspecified" 
      requireAccess="Script" />
    </handlers>

     <environmentVariables>
       <environmentVariable name="SERVER_NAME" value="localhost" />
       <environmentVariable name="SERVER_PORT" value="80" />
     </environmentVariables>
  </system.webServer>

  <appSettings>
    <add key="PYTHONPATH" value="C:\Python313\Lib" />
    <add key="WSGI_HANDLER" value="my_app.wsgi_app()" />
  </appSettings>
</configuration>

Did you try following the official guide from Microsoft? At no point does it seem to mention that simply writing to stdout / print() is enough: every example mentioned, instead, seems to refer to some established framework (bottle/flask/django). Your server config might be expecting a proper entry point, that your helloworld.py doesn’t have.

From the documentation:

<!-- The handler here is specific to Bottle; see the next section. -->
<add key="WSGI_HANDLER" value="app.wsgi_app()"/>

Your own config has:

<appSettings>
  <add key="PYTHONPATH" value="C:\Python313\Lib" />
  <add key="WSGI_HANDLER" value="my_app.wsgi_app()" />
</appSettings>

But there’s no Bottle app in your own helloworld.py, from the looks of it?

I completely gave up on this approach. I will probably never understand how to do this, so I am starting completely over via PyScript . I signed up online and got a project with an index.html, a main.py, and a pyscript.toml. I copied them to my C:\inetpub\wwwroot\cma , reconfigured pyscript.toml to be pyscript.json instead, and it still doesn’t work.

I then tried running via [quote]python -m http.server[/quote] as administrator on the /cma folder and pulling up the URL with port 8000, only to get this:

Error response

Error code: 404

Message: File not found.

Error code explanation: 404 - Nothing matches the given URI.

index.html:

<!DOCTYPE html>
<html lang="en">
<head>
    <title>Hello World</title>

    <!-- Recommended meta tags -->
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1.0">

    <!-- PyScript CSS -->
    <link rel="stylesheet" href="https://pyscript.net/releases/2025.2.1/core.css">

    <!-- This script tag bootstraps PyScript -->
    <script type="module" src="https://pyscript.net/releases/2025.2.1/core.js"></script>
</head>
<body>
    <script type="py" src="main.py" config="pyscript.json"></script>
</body>
</html>

main.py:

from cma import app
from flask import Flask

print("Content-type: text/html")
print("Hello World!")

pyscript.json:

{
	"name": "Hello World",
	"packages": ["wfastcgi", "flask"],
	"appSettings": {
					"PYTHONPATH": "C:/inetpub/wwwroot/cma",
					"WSGI_HANDLER": "cma.app"
                   },
	"system.webServer": {
				"handlers": {
								"name": "PythonHandler",
								"path": "*",
								"verb": "*",
								"modules": "FastCgiModule",
								"scriptProcessor": "C:/Python313/python.exe|C:/Python313/Scripts/wfastcgi.py",
								"resourceType": "Unspecified",
								"requireAccess": "Script"
					        }
			            }
}

Once more, are you completely sure this is the right way to go about it?

As per yet another tutorial, at the very least try to provide:

from flask import Flask
app = Flask(__name__)

@app.route("/hello")
def hello():
   return "Hello Stealth!"

How is your server supposed to know about your app - if all you’re doing is trying to print() to stdout? Do you understand the basics of back-end development, to begin with?

I complete gave up. I can’t do Python like other people can so easily do. I went to one other PyScript tutorial and tried a very simple method to handle using Python as a script, and it is finally working for me.

I couldn’t use Flask at all, and the multitude of tutorials made things even more confusing to me.

Maybe they’re right online when they say that Python is too hard to learn.