I'm trying to get my model deployed on iis, but after I browse the application, it throws Not Found The requested URL was not found on the server. I follow this with web.config
and use wfastcgi
module. At first it was working yet with problem that only server_ip and localhost is accessible, not other client_ip in the same network. When I browse the web keep loading pending documents. So, I did remove application from website in iis and iisreset
At the moment, it seems like Flask throws this error at first and I have no clue what could go wrong? I want to deploy Flask as API endpoint.
My code snippet:
app = Flask(__name__)
model = load_model('./saved_model.keras')
@app.route("/api/index", methods=['GET'])
def index():
return 'Welcome!'
@app.route("/api/predict", methods=['POST'])
def predict():
data = request.get_json()
// Decode and normalize image
print(f'Predicted class: {predicted_class}')
return jsonify({'prediction': str(predicted_class)}), 200
if __name__ == '__main__':
app.run(debug=True)
I add application under Default Web Site in iis that binds to port 80
I'm trying to get my model deployed on iis, but after I browse the application, it throws Not Found The requested URL was not found on the server. I follow this with web.config
https://learn.microsoft.com/it-it/visualstudio/python/configure-web-apps-for-iis-windows?view=vs-2022 and use wfastcgi
module. At first it was working yet with problem that only server_ip and localhost is accessible, not other client_ip in the same network. When I browse the web keep loading pending documents. So, I did remove application from website in iis and iisreset
At the moment, it seems like Flask throws this error at first and I have no clue what could go wrong? I want to deploy Flask as API endpoint.
My code snippet:
app = Flask(__name__)
model = load_model('./saved_model.keras')
@app.route("/api/index", methods=['GET'])
def index():
return 'Welcome!'
@app.route("/api/predict", methods=['POST'])
def predict():
data = request.get_json()
// Decode and normalize image
print(f'Predicted class: {predicted_class}')
return jsonify({'prediction': str(predicted_class)}), 200
if __name__ == '__main__':
app.run(debug=True)
I add application under Default Web Site in iis that binds to port 80
You could follow the below steps to host the flask api on iis and access on the remote machine.
i have this below app.py file:
from flask import Flask, request, jsonify
app = Flask(__name__, static_url_path='/flaskapp')
@app.route("/flaskapp/api/index", methods=['GET'])
def index():
return jsonify({"message": "Welcome to the Flask API!"})
@app.route("/flaskapp/api/predict", methods=['POST'])
def predict():
try:
data = request.get_json()
# Check if required field is present
if "input_data" not in data:
return jsonify({"error": "Missing 'input_data' key in request"}), 400
input_value = data["input_data"]
# Dummy processing: Just return the received value as "predicted_class"
predicted_class = f"Processed: {input_value}"
print(f'Predicted class: {predicted_class}')
return jsonify({'prediction': predicted_class}), 200
except Exception as e: # Move this to the correct indentation level
return jsonify({"error": str(e)}), 500 # Return error response
if __name__ == '__main__':
app.run(host='0.0.0.0', port=5000, debug=True)
use application name which is flaskapp in app = Flask(__name__, static_url_path='/flaskapp')
if you are hosting as application in iis.
In the executable add path:
C:\Python\python.exe|C:\Python\Lib\site-packages\wfastcgi.py
Request path: *
Module: FastCgiModule
Name: Your choice
Select your paython application setting.
There you can see the Environment variable. Add these name value pair.
WSGI_HANDLER: app.app
PYTHONPATH: your application folder full path
wfastcgi.py:
from app import app
if __name__ == "__main__":
app.run()
web.config:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<handlers>
<add name="Python FastCGI" path="*" verb="*" modules="FastCgiModule" scriptProcessor="C:\Python\python.exe|C:\Python\Lib\site-packages\wfastcgi.py" resourceType="Unspecified" requireAccess="Script" />
</handlers>
</system.webServer>
</configuration>
Result:
processPath
in<httpPlatform />
? I have libraries and packages in that. – CChickii Commented Jan 31 at 8:41