0

I have a site defined for my IIS and I have a web.config defined at site level, and my application runs fine if I also define my fastcgi handler at this level.

But I need to make this application available to many different user groups, so I define them as separate applications under the site each with a different code and each running under a separate user and python environment.

For this reason, I need to define my fastcgi handler at the application level.

When I define the fastcgi handler in my web.config at the application level, I just get a blank screen. I have been struggling with this for a long time, I really do not know why it doesn't work at application level.

I think that it is a problem with the routing, but I don't know what I need to modify to fix it.

My web.config:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <handlers>
        <add name="py4webHandler" path="*" verb="*" modules="FastCgiModule" scriptProcessor="D:\Python\Miniconda3\envs\py4web2\python.exe|D:\Data\py4web\wfastcgi.py" resourceType="Unspecified" requireAccess="Execute" />
        </handlers>
    </system.webServer>
        <appSettings>
                <add key="PYTHONPATH" value="D:\Data\py4web" />
                <add key="WSGI_HANDLER" value="app.application" />
                <add key="WSGI_LOG" value="D:\Data\py4web\wfastcgi.log" />
        </appSettings>  
    <system.web>
      <sessionState timeout="60"></sessionState>
    </system.web>
</configuration>

My wsgi handler app:

import os
from py4web.core import wsgi
# BEGIN CONFIGURATION
PASSWORD_FILENAME = 'password.txt'
DASHBOARD_MODE = 'full' # or 'demo' or 'none'
APPS_FOLDER = 'D:/Data/py4web/apps'
password_file = os.path.abspath(os.path.join(os.path.dirname(__file__), PASSWORD_FILENAME))
application = wsgi(password_file=password_file, dashboard_mode=DASHBOARD_MODE, apps_folder=APPS_FOLDER)

Debugging I added to wfastcgi.py When I define my handler at application level (doesn't work):

 'wsgi.path_info': b'/py4web/'
 'PATH_INFO': '/py4web/'
 'PATH_TRANSLATED': 'D:\\Data\\py4web\\'
 'wsgi.query_string': b''
 'QUERY_STRING': ''
 'REQUEST_METHOD': 'GET'
 'REQUEST_URI': '/py4web/'
 'SCRIPT_FILENAME': 'D:\\Data\\py4web\\'

When I define my handler at site level (works):

 'wsgi.path_info': b'/'
 'PATH_INFO': '/'
 'PATH_TRANSLATED': 'C:\\inetpub\\wwwroot\\py4web'
 'wsgi.query_string': b''
 'QUERY_STRING': ''
 'REQUEST_METHOD': 'GET'
 'REQUEST_URI': '/'
 'SCRIPT_FILENAME': 'C:\\inetpub\\wwwroot\\py4web'

I tried many different solutions but up until now the only solution that works is defining the handler in the c:\inetpub\wwwroot\mysite1\web.config

I saw this post: Running Flask via FastCGI in IIS at application level instead of website leve

And it looks similar to the issue that I am facing but I am not sure where I would need to modify the routing for the virtual directory. Help would be appreciated as I have already spent many hours on this.

  • Usually the virtual path is set in .py, your .py file should be wfastcgi.py file. – samwu Feb 07 '23 at 10:17
  • Thanks. I will see if i can find the virtual path in the wfastcgi.py file and see if manipulating it helps. – Davidiam Feb 08 '23 at 09:57
  • I added a lot of debugging in my wfastcgi.py but it didn't help to find the solution. I tried adding routing rewrites in IIS but this also doesn't help. I am close to giving up on this entirely as I have already spent over 40 hours trying to get it work at application level. – Davidiam Feb 22 '23 at 10:14
  • Looks very similar to this question: https://stackoverflow.com/questions/65871980/deleting-an-environmental-variable-for-iis/65872279#65872279 , but mine is not a flask app, but a py4web app (based on ombot). – Davidiam Feb 22 '23 at 10:18

0 Answers0