[Python] I have developed a HTML form and send a request to Heroku server, but no response and...

Discussão em 'Python' iniciado por Stack, Fevereiro 25, 2025.

  1. Stack

    Stack Membro Participativo

    I tried to write a HTML program and send a request to heroku server, but no response.

    1.) HTML program

    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Run Python Program</title>
    <script>

    async function sendData() {

    alert('0');

    // const data = {input: document.getElementById('inputField').value}; //

    const data = {input: document.getElementById('inputField').value};

    alert(data);

    alert(JSON.stringify(data));

    const response = await fetch('https://test-hui-b40ccd43af5f.herokuapp.com//run', {
    method: 'POST',
    headers: {
    'Content-Type': 'application/json',
    },
    body: JSON.stringify(data),
    });

    alert('2');

    const result = await response.json();

    document.getElementById('result').innerText = JSON.stringify(result);
    }
    </script>
    </head>
    <body>
    <h1>Run Python Program</h1>
    <input type="text" id="inputField" placeholder="Enter input">
    <button onclick="sendData()">Submit</button>
    <h2>Result:</h2>
    <pre id="result"></pre>
    </body>
    </html>


    python request flasktest.py

    # app.py
    from flask import Flask, request, jsonify
    import os

    app = Flask(__name__)

    @app.route('/run', methods=['POST'])
    def run_program():
    data = request.json
    # Process the data (e.g., run your Python program)
    result = your_python_function(data) # Replace with your function
    return jsonify(result)

    def your_python_function(data):
    # Example processing
    return {'message': 'Processing complete', 'input': data}

    if __name__ == '__main__':
    app.run(host='0.0.0.0', port=int(os.environ.get('PORT', 5000)))


    Procfile :
    Procfile


    requirements.txt
    requirements.txt


    I have opened the HTML file type in something on input text and press 'Submit' button. no response and checking the log. an error code H10 comes out.

    2025-02-25T03:24:17.739378+00:00 heroku\[router\]: at=error code=H10 desc="App crashed" method=OPTIONS path="//run" host=test-hui-b40ccd43af5f.herokuapp.com request_id=7445a6a7-8f08-4683-aab4-a9b97389180a fwd="58.153.66.113" dyno= connect= service= status=503 bytes= protocol=https


    I tried to change the script many times and found a lot of help. But no use. Hope someone can help.

    Continue reading...

Compartilhe esta Página