From time to time, we want to run and execute python scripts in a windows server based on IIS web server. In this tutorial, I am going to describe steps that are needed to enable IIS in windows Server.
Login as a Administrator in your windows server and open server manager
go to Add Roles and features then click next until you see the following screen
be sure to select all of the roles in the following picture
then click next and then installed this roles.
Now we need to install python in windows server.
go to the python site and download the package with name “Download Windows installer (64-bit)“
After download, open setup file and choose the following option
then go to customize installation and make sure that all options have been selected
for installation location select c:\Python311
After install open IIS manager. in windows menu type inetmgr to open iis manager.
In IISManager open HandlerMapping
then on the right menu go to Add Script Map Section
then enter following data
Pay attention to Executable path !!!
if you enter your installation path incorrectly the script won’t work.
then click on OK and close the dialog.
if you see the following message just click Yes
then go to CMD(command Prompt) and install following package
pip install art
now the server is ready to serve Python files. In order to test go to c:\inetpub\wwwroot and create a sample file with name test.py. in this file just paste the following code
from art import *
Art=text2art("TEST",font='block',chr_ignore=True)
print('Content-Type: text/plain')
print('')
print('Mousavi.dev')
print(Art)
Save file then open browser and enterthe IPaddress of you server x.x.x.x/test.py you will see the following site.
I hope this article come handy.
Please leave a comment if you encounter any problem 🙂