0

Edit: Originally thought this was IIS issue, but looks like it's FastCgiModule causing the issue.

To be clear, the WebApp itself works, it only fails when I choose "Image Test" from the dropdown (see code below) menu on the site. Specifically, it fails on the df.plot line, and I can't figure out why.

from flask import Flask, request
import pandas as pd

app = Flask(__name__)

html = '''
<h1>Discovery Capital</h1>
<h2>Report Generator</h2>
<p>
<form action="/submitted" method="post">
  <label for="reports">Choose a Report:</label>
  <select id="reports" name="reports">
    <option value="img_test">Image Test</option>
  </select>
  <input type="submit">
</form>
'''

@app.route("/")
def index():
    return html

@app.route("/submitted", methods=['POST'])
def show():
    select = request.form.get("reports")

    if select == 'img_test':
        df = pd.DataFrame([1,2,3,4,5])
        df.plot()
        plt.close()
        result = "Success"

    else:
        result = "Not Available"

    return result

if __name__ == "__main__":
    app.run()

Appreciate the help!

Edit: Here's the log from failed request tracing: enter image description here

David Yang
  • 2,101
  • 13
  • 28
  • 46
  • 1
    Try using FRT to view details about the 500 error, which will generate a detailed log file to help you identify the problem. This link provides the steps to enable failed request tracing: https://learn.microsoft.com/en-us/iis/troubleshoot/using-failed-request-tracing/troubleshooting-failed-requests-using-tracing-in-iis – YurongDai Dec 29 '22 at 05:44
  • Thanks Yurong, I've enabled failed request tracking, seems like the issue is with FastCgiModule? Still not really giving me details. I've uploaded a picture of the trace in OP. – David Yang Feb 02 '23 at 16:22
  • In fact, FRT just ruled out IIS components from the scope. You configured Python on IIS via FastCGI, and that wfastcgi or your Python code/framework was the cause of 500 errors. You will have to debug them to learn more. – Lex Li Feb 02 '23 at 16:37
  • Okay, so the IIS configuration is fine, and my Flask app runs on localhost without issue. The exact line of code causing the 500 error is `df.plot()`, so it's some FastCGI issue? – David Yang Feb 02 '23 at 16:43
  • 1
    If you review your current configuration, you will see that an obsolete module wfastcgi is what you used to tie Python to IIS, https://pypi.org/project/wfastcgi/ It is known to have bugs and nobody works on it for years. – Lex Li Feb 02 '23 at 16:46
  • I see, what is the alternative to wfastcgi? – David Yang Feb 02 '23 at 16:48
  • 1
    One option https://halfblood.pro/running-flask-web-apps-on-iis-with-httpplatformhandler/ – Lex Li Feb 02 '23 at 18:05

0 Answers0