-2

I have a simple flask app that works locally but gets 500'd when testing in IIS.

Edit: I was wrong, initially thought was pandas read issue but the issue is actually coming from subprocess that tries to get the user's IP address:

from flask import Flask, request

import subprocess

app = Flask(__name__)

html = '''
<h1>Test</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="user_test">User 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 == 'user_test':

        name = 'XXXXXXXX.dcm.com'
        result = subprocess.check_output(['nslookup', name])

    else:
        result = "Not Available"
    return result

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

This code runs fine when tested locally. If I remove the part where it runs subprocess to get user IP that works fine on IIS. The trouble is when I try to include the part that runs subprocess.check_output(['nslookup',name]) when running on IIS, which leads to 500 internal server error.

Here is picture of error:

enter image description here

Thanks for the help!

David Yang
  • 2,101
  • 13
  • 28
  • 46
  • On a side note, pandas [recommends](https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.values.html#pandas-dataframe-values) using `to_numpy()` instead of `values`. – Jonathan Ciapetti Dec 15 '22 at 00:32
  • What exactly is showed in the 500 error page? Edit the question to include a full screen shot. – Lex Li Dec 15 '22 at 04:41

1 Answers1

0

1.You need "import pandas as pd" at top.

2.The error doesn't happen when reading csv, but on the return process. "df.values" cannot be returned at this situation because "df" is Dataframe type. Instead, you can use:

df = pd.read_csv("uuids.csv")

return df.to_html(header="true", table_id="table")

or

return df.to_csv()

or

return render_template("xxx.html"......)

Qiang Fu
  • 1,401
  • 1
  • 2
  • 8
  • 1
    Thanks for the response, but I accidentally excluded my pandas import from the example script. It still fails on read. In fact even if I remove the line that gets values from df, and just set my result = 'Hello', it fails – David Yang Dec 15 '22 at 16:32
  • Hey this is my bad, see edits on OP, I was wrong -- the error is coming from subprocess nslookup – David Yang Dec 15 '22 at 16:56