[Python] Flutter help needed: 404 not found flask

Discussão em 'Python' iniciado por Stack, Março 20, 2025.

  1. Stack

    Stack Membro Participativo

    I am attempting to run a flask backend server with flask. Whenever I run:

    python3 server.py


    The server hosts and whenever I go to it, it gives an error 404 not found. Here is the code:

    from flask import Flask, request, jsonify
    from flask_cors import CORS
    import subprocess

    app = Flask(__name__)
    CORS(app) # Enable CORS for all routes

    @app.before_request
    def before_request():
    print(f"Request path: {request.path}")

    @app.route('/execute-file/', methods=['POST'])
    def execute_file():
    try:
    # Get the file name from the request body
    fileName = request.form.get('fileName')
    if not fileName:
    return jsonify({'success': False, 'error': 'File name not provided'})

    # Execute the file
    result = subprocess.run(['python', f'lib/execute/{fileName}'], capture_output=True, text=True)

    if result.returncode == 0:
    return jsonify({'success': True, 'output': result.stdout})
    else:
    return jsonify({'success': False, 'error': result.stderr})
    except Exception as e:
    return jsonify({'success': False, 'error': str(e)})

    if __name__ == '__main__':
    app.run(host='0.0.0.0', port=8000)


    The error itself says: Not Found The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again. console displays the following:

    * Serving Flask app 'server'
    * Debug mode: off WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.
    * Running on all addresses (0.0.0.0)
    * Running on http://127.0.0.1:8000
    * Running on http://192.168.1.21:8000
    Press CTRL+C to quit
    Request path: / 127.0.0.1 - - [20/Mar/2025 19:11:22] "GET / HTTP/1.1" 404 -

    Continue reading...

Compartilhe esta Página