strongbad
strongbad

Reputation: 143

django on IIS, process exited unexpectedly

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:

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.

Upvotes: 4

Views: 5135

Answers (2)

Jingkai Xu
Jingkai Xu

Reputation: 31

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

Upvotes: -3

JohnTsai
JohnTsai

Reputation: 33

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.

Upvotes: 2

Related Questions