4

I have read every article I could find on this topic but I'm still unable to run django project on IIS. The error message is 500 Internal Server Error, c:\program files (x86)\python 3.5\python.exe - The FastCGI process exited unexpectedly.

Tracing rule for error 500 provides the following:

Error 
-FASTCGI_UNEXPECTED_EXIT 


Warning 
-SET_RESPONSE_ERROR_DESCRIPTION 


ErrorDescription
c:\program files (x86)\python 3.5\python.exe - The FastCGI process exited unexpectedly 


Warning 
-MODULE_SET_RESPONSE_ERROR_STATUS 


ModuleName
FastCgiModule 

Notification
EXECUTE_REQUEST_HANDLER 

HttpStatus
500 

HttpReason
Internal Server Error 

HttpSubStatus
0 

ErrorCode
The system cannot find the file specified.
(0x2) 

environment:

  • Windows Server 2012 R2
  • IIS 8.5 (CGI enabled)
  • wfastcgi installed and enabled (command "c:\program files (x86)\python 3.5\python.exe|c:\program files (x86)\python 3.5\lib\site-packages\wfastcgi.py" opens a python shell - is this right?)

web.config under c:\inetpub\wwwroot\testapp:

<configuration>
<system.webServer>
<handlers>
  <add name="Python FastCGI" path="*" verb="*" modules="FastCgiModule" scriptProcessor="c:\program files (x86)\python 3.5\python.exe|c:\program files (x86)\python 3.5\Lib\site-packages\wfastcgi.py" resourceType="Unspecified" requireAccess="Script" />
</handlers>
    <tracing>
        <traceFailedRequests>
            <add path="*">
                <traceAreas>
                    <add provider="ASP" verbosity="Verbose" />
                    <add provider="ISAPI Extension" verbosity="Verbose" />
                    <add provider="WWW Server" areas="Authentication,Security,Filter,StaticFile,CGI,Compression,Cache,RequestNotifications,Module,FastCGI,WebSocket" verbosity="Verbose" />
                </traceAreas>
                <failureDefinitions statusCodes="500" />
            </add>
        </traceFailedRequests>
    </tracing>
</system.webServer>

<appSettings>
 <!-- Required settings -->
 <add key="WSGI_HANDLER" value="django.core.wsgi.get_wsgi_application()" />
 <add key="PYTHONPATH" value="c:\inetpub\wwwroot\testapp" />

 <!-- Optional settings -->
 <add key="WSGI_LOG" value="C:\inetpub\logs\testapp.log" />
 <add key="WSGI_RESTART_FILE_REGEX" value=".*((\.py)|(\.config))$" />
 <add key="APPINSIGHTS_INSTRUMENTATIONKEY" value="__instrumentation_key__" />
 <add key="DJANGO_SETTINGS_MODULE" value="testapp.settings" />
</appSettings>
</configuration>

thanks for any help.

strongbad
  • 133
  • 1
  • 4
  • 12
  • in this environment python is 3.5.1 and wfastcgi is 2.2. On another server with Server 2008 R2, Python 3.4 and wfastcgi 2.1 it works just like in every article on web. I'm confused to say the least – strongbad Apr 19 '16 at 12:20
  • any luck figuring this out? having the same issue. 3.4 works fine, 3.5 doesn't – Progger Jan 06 '17 at 22:12
  • Nope but 3.4 seems to work fine so I'm ok with that. – strongbad Jan 08 '17 at 09:01
  • 2
    just so you know, I got it working. I changed my app pool from applicationpoolidentity to LocalService, used a virtual environment, and gave iusr rights to the virtual environment. took me 3 days to figure this out but I got it working. – Progger Jan 08 '17 at 23:15
  • thanks for the heads up! – strongbad Jan 09 '17 at 13:00

2 Answers2

2

I've spent lot of time to solve this problem and finally made it. I'll share some tips that I've tried.

Environment

  • Windows Server 2012 R2
  • IIS 8.5 (CGI enabled)
  • python 3.6.6
  • wfastcgi 3.0.0

1. Folder permission

Since message FASTCGI_UNEXPECTED_EXIT showed up, IIS had permission to access folders 'project folder' and 'virtualenv folder'

For those who only got 500 Error but no message, try granting folder permissions to IIS AppPool\<myapppoolname>

(Reference: https://support.pkware.com/display/SMAR/KB+-+Granting+folder+permissions+to+IIS+application+pools)

If you're placing your under default AppPool, grant access to IUSR and IIS_IUSRS.

2. Install Python Properly

Reference: https://github.com/microsoft/PTVS/issues/5450

I used to install python under user folder instead of C:\Python36. So I removed and re-installed with executable installer downloaded from https://python.org/downloads

Some configurations:

  1. Add Python to Path
  2. Install for all users
  3. Location C:\Python36

Note that I am using virtual environment. But I know many tutorials don't and they seems working fine, so feel free to use or not.

JohnTsai
  • 33
  • 1
  • 7
-3

I had the same issue, my solution was try to run your project locally,

python manage.py runserver

and see if you can run the project. In my case, my numpy was broken, so it leads to the wfastcgi exited. Maybe your wfastcgi is perfect, but some other python packages are not working

Jingkai Xu
  • 31
  • 2