HttpPlatformHandler error with Django app hosted in IIS

143 Views Asked by At

I have a Django site I'm developing, which uses Waitress as the WSGI server. When I run the server.py file from the command line, everything works as expected.

As a next step toward rolling it out, I'm trying to "wire in" the application to the Windows IIS web server. After a lot of searching around I found this article which is fairly recent and provides a comprehensive set of steps to get it working with HttpPlatformHandler (which I take to be the preferred option, as Microsoft reports they are no longer maintaining WFastCGI). I also took into account the author's caveat regarding lack of expertise, which is why I'm using Waitress rather than the Django development server as he did.

The issue I'm having is that with IIS configured to host the Django app, the browser connection never goes through. While the browser makes its connection attempt, the Windows event log on my server shows a recurring error every minute or so:

enter image description here

Note, each time the error is triggered, the process number and port number are both different; the Error Code of -2147023436 however is always the same.

Additionally, each time the error occurs a new log file is generated in my Django project folder, but the file is completely empty.

enter image description here

I did the usual google searches for the HttpPlatformHandler error code and event ID but didn't find anything helpful (to me). I'd appreciate any kind of pointer to where the problem might be.

Further info about the environment I'm using:

  • Windows Server 2016 Standard
  • IIS Version 10
  • HttpPlatformHandler 1.2
  • Python 3.10.11
  • Django 4.2.7
  • Waitress 2.1.2

server.py file:

from waitress import serve
from django_project.wsgi import application

if __name__=='__main__':
    serve(application, port='8090')

web.config file:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.webServer>
    <handlers>
            <add name="hphForCSCR" path="*" verb="*" modules="httpPlatformHandler" resourceType="Unspecified" />
      <add name="PythonHandler" path="*" verb="*" modules="httpPlatformHandler" resourceType="Unspecified" />
    </handlers>
    <httpPlatform processPath="D:\mystuff\django-projects\code\cscr\.venv\Scripts\python.exe" arguments="D:\mystuff\django-projects\code\cscr\server.py" startupTimeLimit="60" stdoutLogEnabled="true" stdoutLogFile="D:\mystuff\django-projects\code\cscr\server.log" processesPerApplication="1">
      <environmentVariables>
        <environmentVariable name="SERVER_PORT" value="8090" />
      </environmentVariables>
    </httpPlatform>
  </system.webServer>
    <appSettings>
        <add key="PYTHONPATH" value="D:\mystuff\django-projects\code\cscr" />
        <add key="WSGI_HANDLER" value="django.core.wsgi.get_wsgi_application()" />
        <add key="DJANGO_SETTINGS_MODULE" value="django_project.settings" />
    </appSettings>
</configuration>

Site settings in IIS (note, the listen port is 8080 intentionally -- I already realized that putting it on 8090 caused a conflict with waitress):

enter image description here

Handler mapping:

enter image description here

0

There are 0 best solutions below