Flask app getting 0x8007000d error with IIS

0

I'm trying to get a very basic flask app to work on IIS 10 running on Windows Server 2019. I followed the HTTPPlatform Handler instructions from: https://docs.microsoft.com/en-us/visualstudio/python/configure-web-apps-for-iis-windows?view=vs-2019

But I keep getting HTTP 500.19 errors with error code 0x8007000d. From googling, I suspect the problem is in my web.config, but I don't know what is wrong. The app works fine from the command line. This is my web.config:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.webServer>
    <handlers>
      <add name="PythonHandler" path="*" verb="*" modules="httpPlatformHandler" resourceType="Unspecified"/>
    </handlers>
    <httpPlatform processPath="D:\python39\python.exe"
                  arguments="D:\inetpub\wwwroot\flasktest.py"
                  stdoutLogEnabled="true"
                  stdoutLogFile="d:\logs\python.log"
                  startupTimeLimit="60"
                  processesPerApplication="16">
      <environmentVariables>
        <environmentVariable name="SERVER_PORT" value="9010" />
      </environmentVariables>
    </httpPlatform>
  </system.webServer>
</configuration>
This is my app.py:

from flask import Flask, render_template

app = Flask(__name__)
#app.debug = True

@app.route("/", methods=('GET', 'POST'))
def home():
  return render_template('main.html', hello = 'hello world')

if __name__ == '__main__':
    app.run(host='0.0.0.0',port=9010)

this is my main.html

{% extends 'layout.html' %}
{% block content %}
  <div class="container">
    <div class="leftrow1">
      {{ hello }}
    </div>
    <div class="leftrow2">
    </div>
    <div class="leftrow3">
    </div>
    <div class="leftrow4">
    </div>

    <div class="main_frame_1">
    </div>
    <div class="main_frame_2">
    </div>
  </div>
{% endblock content %}

and this is the layout.html

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
    <link rel="stylesheet" type="text/css" href="/static/css/style.css"/>
</head>
<body>
  {% block content %} 
  {% endblock content %}
</body>
Update: based on comments received, adding additional error info This is the error I get (without installing httpplatformhandler), nothing is in eventlog when this occurs: 500.19 error message This is the error I get after installing httpplatformhandler: 500.3 error message with the 500.3 message, I also get a bunch of event 1000 from HttpPlatformHandler in event log: enter image description here

flask
iis
asked on Stack Overflow Nov 24, 2020 by Ching Liu • edited Nov 25, 2020 by Ching Liu

1 Answer

0

It seems that you don't have the correct permission to access D:\python39\python.exe and D:\inetpub\wwwroot\flasktest.py.

  1. Open IIS Manager -> Select the site you added the HttpPlatformHandler

  2. Click Handler Mappings in the feature view -> select the HttpPlatformHandler

  3. Click Edit Feature Permission in the Action Panel

  4. Make sure you have check the Execute permission

answered on Stack Overflow Nov 26, 2020 by samwu

User contributions licensed under CC BY-SA 3.0