Sathish Kumar
Sathish Kumar

Reputation: 2606

How to deploy Python application using CGI on IIS?

I am new to python and I try to deploy a simple hello python application on IIS and I followed this URL

https://support.sisense.com/hc/en-us/community/posts/115007362727-Installing-Python-on-IIS

Hello.py

print "Content-type:text/html\r\n\r\n"
print '<html>'
print '<head>'
print '<title>Hello Word - First CGI Program</title>'
print '</head>'
print '<body>'
print '<h2>Hello Word! This is my first CGI program</h2>'
print '</body>'
print '</html>'

However, it error's as mentioned below

HTTP Error 401.3 - Unauthorized
You do not have permission to view this directory or page because of the access control list (ACL) configuration or encryption settings for this resource on the Web server

I feel the issue may not be related to permission as I am able to browse hello.html

I tried some of the solutions provided in SO to resolve the issue but nothing worked. Any help is highly appreciated

Upvotes: 5

Views: 4756

Answers (1)

Jalpa Panchal
Jalpa Panchal

Reputation: 12814

To configure Python with IIS you can try to follow the below steps:

  1. Download the latest Python version because IIS will not work with the python old version.

https://www.python.org/downloads/windows/

  1. Below is the hello.py file:
print("Content-type:text/html\r\n\r\n")
print('<html>')
print('<head>')
print('<title>Hello Word - First CGI Program</title>')
print('</head>')
print('<body>')
print('<h2>Hello Word! This is my first CGI program</h2>')
print('</body>')
print('</html>')
  1. Enable IIS CGI feature.

enter image description here

  1. Open IIS Manager. Right-click on the server name and select add site.

enter image description here

  1. Add site binding detail folder path (python folder)

enter image description here

  1. Select a site and click on the handler mapping from the middle pane.

enter image description here

  1. Click on add script map from the action pane.

enter image description here

  1. Add script mapping value.

*.py, and map it to c:\Python37-32\python.exe %s %s.

enter image description here

enter image description here

Make sure directory browsing is enabled.

enter image description here

web.config file:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <handlers>
            <add name="python" path="*.py" verb="*" modules="CgiModule" scriptProcessor="C:\Python37-32\python.exe %s %s" resourceType="File" />
        </handlers>
        <directoryBrowse enabled="true" />
    </system.webServer>
</configuration>

Set iis_iusrs and iusr permission to the site folder(c:\pythonapp) and python folder(C:\Python37-32). Make sure anonymous authentication is enabled, and the application pool is set to the application pool identity. After making all the changes restart IIS server and browse the site.

enter image description here

Upvotes: 5

Related Questions