I Want to Host my Python Rest API on Windows 10 IIS server.
First I tried to host a sample application but can not able to that.
my_app.py
from flask import Flask app = Flask(__name__) @app.route('/') def index(): return 'Hello IIS from Flask framework.' @app.route('/Hello') def hello_world(): return 'Hello World!' if __name__ == '__main__': app.run()
web.config
<configuration> <system.webServer> <handlers> <add name="Python FastCGI" path="*" verb="*" modules="FastCgiModule" scriptProcessor="C:Program FilesPython39python.exe|C:Program FilesPython39libsite-packageswfastcgi.py" resourceType="Unspecified" requireAccess="Script" /> </handlers> </system.webServer> <appSettings> <add key="WSGI_HANDLER" value="my_app.app" /> <!-- {name_of_file}.{name_of_flask_app}--> <add key="PYTHONPATH" value="C:inetpubwwwroottest" /> <add key="WSGI_LOG" value="C:inetpubwwwroottestapp.log" /> </appSettings> </configuration>
I have tried the below tutorials but it is not working for me.
https://medium.com/@rajesh.r6r/deploying-a-python-flask-rest-api-on-iis-d8d9ebf886e9
https://www.youtube.com/watch?v=ma1UvzqF82Q&ab_channel=ShobhitWalia
HTTP Error 500.0 – Internal Server Error : see the Error scrennshot
I need help…. Thanks
Advertisement
Answer
If you want IIS host python application, you need to install python, and then you need to add module mapping in IIS. Here are the steps:
First install python on your computer.
Enable CGI:
After successful installation, you will see “ISAPI and CGI Restrictions” and Handler Mappings:
- Enter “ISAPI and CGI Restrictions”, add a new ISAPI or CGI Restrictions:
- Enter “Handler Mappings”, then add Module Mapping(%S %S needs to be added or an error will be reported):
Finally we can successfully access the python Application:
UPDATE:
Can you see python in your Handler Mappings?
This is my web.config:
<?xml version="1.0" encoding="UTF-8"?> <configuration> </configuration>
There is nothing in web.config. All my settings are for the entire IIS:
Click “Directory Browsing”:
Enable it: