Q: Flask Permission Error when deployed to IIS I deployed a flask app to IIS using FastCGI and WSGI Handler. The steps that I have followed are

*

*Created a virtual environment for Python and installed all packages including wfastCGI.

*Set the Handler mappings and included the FastCGI settings.

*Assigned the necessary permissions for the folders by adding IIS_IUSRS and IUSR.

Below is the medium link that I followed in terms of the steps.
https://medium.com/@dpralay07/deploy-a-python-flask-application-in-iis-server-and-run-on-machine-ip-address-ddb81df8edf3
The folder structure for the code is as shown below with (checkin_env) being the virtual environment.


Fast CGI settings are shown as below with WSGI Handler being checkFlask.app

The web.config file which was generated is here.

When I tried running on Ports 80, 5000 I received a permission error related to System32 which I am totally confused and unsure about. Any thoughts or inputs are highly appreciated. Thank you.


A: You could follow the below steps to run the flask app from the virtual environment:
1)Install python on your machine:
Note: Use python version above 3.6.
at the time of installation you have to remember the below things:
select customize the installation and add python to the path.

in advance setting you have selected for all users and installed at c drive:

2)Create and Configure a Python Virtual Environment for Your Application:
-Open a Command Prompt.
-Navigate to the root of the C: drive: cd C:\
-Create a new directory in which to store your virtual environments:
mkdir virtualenvs
-Navigate to the newly created virtualenvs directory:
cd virtualenvs
-Create a new virtual environment. python -m venv test
3)Activate the Virtual Environment and Upgrade pip:
-Open a Command Prompt
-Navigate to the virtual environment's directory:
cd C:\virtualenvs\test

-Activate the virtual environment:
Scripts\activate.bat

-At this point you will see (test) at the beginning of the command prompt, indicating the virtual environment is active:

-run the below command to install pip and wfastcgi:
python -m pip install — upgrade pip
pip install wfastcgi

4)install flask:
pip install flask

5)create a site in iis:
-Create a new site in IIS and set the folder path of your flask application:

6)Configure handle mapping for site:
-Select your site, Double click "Handler Mappings"

-Click "Add Module Mapping"

-Click "Request Restrictions". Make sure "Invoke handler only if request is mapped to:" checkbox is unchecked:

Click "Yes" here:

-Go to the root server settings and click "FastCGI Settings":

-Double click it, then click the "…" for the Environment Variables collection to launch the EnvironmentVariables Collection Editor.
-Set the PYTHONPATH variable:

-And the WSGI_HANDLER (my Flask app is named hello.py so the value is app.app - if yours is named site.py it would be site.app or similar):

-Click OK and browse to your site:

web.conifg file:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <handlers>
            <add name="flasktest" path="*" verb="*" modules="FastCgiModule" scriptProcessor="C:\virtualenvs\test\Scripts\python.exe|C:\virtualenvs\test\Lib\site-packages\wfastcgi.py" resourceType="Unspecified" />
        </handlers>
    </system.webServer>
</configuration>


A: The issue was with some libraries inside the checkFlask.py file which included IPython.display. Code worked fine after removing those libraries. Marking this as resolved for now. Here is a reference link for the solution I found. https://community.esri.com/t5/python-questions/are-wfastcgi-python-api-compatible/m-p/76578#M6215
