0

Windows Server DataCenter 2019 Python 3.7.6

I have 2 sites configured on IIS.

mysite1 port 9090: Runs using VSCode and entering URL in browser

  1. Runs from VSCode
  2. Enter URL in Browser: ###.###.###.###:9090

mysite2 port 9566: Only runs from VSCode

  1. Runs from VScode.
  2. ERROR 500. Enter URL in Browser: ###.###.###.###:9566 Also from IIS Manager menu option: Browse *:9566

HTTP Error 500.0 - Internal Server Error

C:\inetpub\wwwroot\Flask\mysite2\venv\Scripts\python.exe - The FastCGI process exited unexpectedly

Detailed Error Information:

Module FastCgiModule

Notification ExecuteRequestHandler

Handler Python FastCGI

Error Code 0x00000067

Requested URL http://localhost:9566/

Physical Path C:\inetpub\wwwroot\Flask\mysite2

Logon Method Anonymous

Logon User Anonymous

The 2 sites are configured with different AppPools

2 web.config files

<configuration>  
  <system.webServer>
    <handlers>
        <remove name="FlaskHandler" />
        <add name="Python FastCGI" path="*" verb="*" modules="FastCgiModule" scriptProcessor="C:\inetpub\wwwroot\Flask\mysite1\venv\Scripts\python.exe|C:\inetpub\wwwroot\Flask\mysite1\venv\lib\site-packages\wfastcgi.py" resourceType="Unspecified" requireAccess="Script" />
    </handlers>
  </system.webServer>
  <appSettings>
    <add key="WSGI_HANDLER" value="app.app" /> <!-- {name_of_file}.{name_of_flask_app}-->
    <add key="PYTHONPATH" value="C:\inetpub\wwwroot\Flask\mysite1" />
    <add key="WSGI_LOG" value="C:\inetpub\wwwroot\Flask\mysite1\app.log" />
  </appSettings>
</configuration>  

<configuration>  
  <system.webServer>
    <handlers>
        <remove name="FlaskHandler" />
        <add name="Python FastCGI" path="*" verb="*" modules="FastCgiModule" scriptProcessor="C:\inetpub\wwwroot\Flask\mysite2\venv\Scripts\python.exe|C:\inetpub\wwwroot\Flask\mysite2\venv\lib\site-packages\wfastcgi.py" resourceType="Unspecified" requireAccess="Script" />
    </handlers>
  </system.webServer>
  <appSettings>
    <add key="WSGI_HANDLER" value="app.app" /> <!-- {name_of_file}.{name_of_flask_app}-->
    <add key="PYTHONPATH" value="C:\inetpub\wwwroot\Flask\mysite2" />
    <add key="WSGI_LOG" value="C:\inetpub\wwwroot\Flask\mysite1\app.log" />
  </appSettings>
</configuration>  

The same steps were used to create mysite1 and mysite2.

In IIS manager, I stopped mysite1 but mysite2 does not run using entering URL in a browser.

Help is appreciated 1

More Debugging

  1. I turned on Failed Request Tracing

https://learn.microsoft.com/en-us/iis/troubleshoot/using-failed-request-tracing/troubleshooting-failed-requests-using-tracing-in-iis

These are the Error and Warning traced log messags

94. FASTCGI_UNEXPECTED_EXIT

Error

95. SET_RESPONSE_ERROR_DESCRIPTION     22:01:34.515 

Warning
 ErrorDescription="C:\inetpub\wwwroot\Flask\mysite2\venv\Scripts\python.exe - The FastCGI process exited unexpectedly" 22:01:34.515 
96. MODULE_SET_RESPONSE_ERROR_STATUS

Warning
 ModuleName="FastCgiModule", Notification="EXECUTE_REQUEST_HANDLER", HttpStatus="500", HttpReason="Internal Server Error", HttpSubStatus="0", ErrorCode="The semaphore cannot be set again.
 (0x67)", ConfigExceptionInfo="" 

Debug Post: Python flask app on IIS not working on Windows Server 2019

I do not understand what running wfastcgi.py does but both mysite1 and mysite2 behave the same way.

The "working" site, runs and does not end
C:\inetpub\wwwroot\Flask\RESTAPI_mysite1\venv\Scripts\python.exe C:\inetpub\wwwroot\Flask\mysite1\venv\lib\site-packages\wfastcgi.py

The "non-working" site, runs and does not end
C:\inetpub\wwwroot\Flask\RESTAPI_mysite2\venv\Scripts\python.exe C:\inetpub\wwwroot\Flask\mysite2\venv\lib\site-packages\wfastcgi.py
  1. Debug Post: Getting 500 Internal Server Error when setting up Python and Flask with FastCgiModule on Windows

The suggestions did not work for mysite2.

Help is appreciated 2

G. Young
  • 41
  • 1
  • 7
  • "Only runs from VSCode"? Did you run application via VScode and it report error? I'm not sure if vscode can use IIS or IIS express. However, according to the error code. If site2 ran on IIS, you need to assign iusr and iis_user full permission for the python folder and site folder. – Bruce Zhang Aug 16 '21 at 06:59
  • I ran mysite1 and mysite2 in VSCode to validate the code works. * TESTING: Permissions are the same on mysite1 and mysite2. 1) IIS_IUSRS(SRV1\IIS_IUSRS): Modify, Read & execute, List folder contents, Read, Write. 2) IIS_AppPool\mysite1, IIS_AppPool\mysite2: Read and execute, List folder contents, Read. 3) mysite2. Same Error 500. 4) mysite2. Added IUSR ( does not exist on mysite1): Full control. Same Error 500. – G. Young Aug 16 '21 at 20:29
  • What about create a simple empty app only with hello world in port 9566 on IIS? If it isnot permission issue and fastcgi has pointed to execute file correctly, I think we need to concern about app itself. The error Code 0x00000067 only can be caused by permission and fastcgi points to file. – Bruce Zhang Aug 17 '21 at 08:20
  • 1) Has anyone run multiple IIS Flask sites with Python version >= 3.7? wfastcgi support ends at Python version 3.6. https://pypi.org/project/wfastcgi/ 2) Bruce - mysite2 app is a simple Hello World. – G. Young Aug 18 '21 at 22:13
  • mysite2 works when I use mysite1 AppPool!! I deleted mysite2 AppPool and created a new AppPool exactly matching the characteristics of mysite1's AppPool. Same Error 500 - does not work. I used the DefaultAppPool - Same Error. Help is appreciated. – G. Young Aug 19 '21 at 22:34

1 Answers1

0

It is strange about the application pool. Maybe some special settings of site1 app pool are unknow. Even you create a new pool manually, those settings arenot configured in new pool.

Try to use appcmd to copy the site1 pool to new pool.(Stop site1 pool firstly)

  1. Run command line as administrator.
  2. CD C:\Windows\System32\inetsrv
  3. appcmd.exe list apppool "site1 pool name" /config /xml > D:\AppPoolConfig.xml
  4. appcmd.exe add apppool /name:new pool name /in < D:\AppPoolConfig.xml

Then start the new pool in IIS Manager. Make site2 work on it.

Bruce Zhang
  • 2,880
  • 1
  • 5
  • 11
  • Copying mysite1's AppPool worked!! I'll build more complicated mysite3 and mysite4 and test all 4 work. I'll post results in a few days. Thank you – G. Young Aug 23 '21 at 10:30