admin管理员组文章数量:1313794
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/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
Share Improve this question asked Jan 31 at 4:07 CChickiiCChickii 95 bronze badges 5 |1 Answer
Reset to default 0You 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.
- Create new application in iis with the folder path where you have app.py file. Make sure you have created new app pool for this application with below configuration.
- Go to the iis and select your application from the left pane.
- Double click Handler mapping
- Click Add module mapping from Action pane
- Set the values as shown below:
In the executable add path:
C:\Python\python.exe|C:\Python\Lib\site-packages\wfastcgi.py
Request path: *
Module: FastCgiModule
Name: Your choice
- Now go back and select server node where you can see the FastCGISetting
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
- Set the iis site bindings with the http and port 5000 or any of your choice
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>
- Set iis_iusrs and iusr permission to the site root folder and python root folder.
- Add inbound rule in firewall with the port number 5000 so that remote machine can access this site.
Result:
本文标签: pythonFlask Not Found The requested URL was not found on the serverStack Overflow
版权声明:本文标题:python - Flask: Not Found The requested URL was not found on the server - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741926846a2405340.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
processPath
in<httpPlatform />
? I have libraries and packages in that. – CChickii Commented Jan 31 at 8:41