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:
Thanks for the help!
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"......)