[Python] Flask app with flask-ngrok stuck in Colab (no public URL, cell runs indefinitely,...

Discussão em 'Python' iniciado por Stack, Julho 11, 2025.

  1. Stack

    Stack Membro Participativo

    I'm trying to run a simple Flask chatbot app in Google Colab, using flask-ngrok to expose it publicly. I began developing locally but I ran into some Tensorflow import issues and moved to Colab. However, even after installing flask-ngrok and setting my ngrok authtoken, the cell hangs and only shows:


    (along with a ton of other nonsense error log messages.)

    I don't get the "https://xxxx.ngrok.io" public URL, and when I try to visit 127.0.0.1 link, I get: "Access to 127.0.0.1 was denied, HTTP ERROR 403"

    I have already done these things:

    1.) Restarted the Colab runtime

    2.) Installed both flask-ngrok and pyngrok==4.1.1

    3.) Set my ngrok authtoken (confirmed it's from the ngrok dashboard)

    Here is my code:

    !pip install flask pyngrok
    from pyngrok import ngrok
    ngrok.set_auth_token("my_auth_token")


    from flask import Flask, request, jsonify, render_template

    from pyngrok import ngrok
    import threading

    app = Flask(__name__, template_folder='templates')
    app.debug = False
    run_with_ngrok(app)

    @app.route("/")
    def index():
    return render_template("index.html")

    @app.route('/handle_message', methods=['POST'])
    def handle_message():
    message = request.json['message']
    intents_list = predict_class(message)
    response = get_response(intents_list, intents)
    return jsonify({'response': response})

    if __name__ == "__main__":
    app.run()

    public_url = ngrok.connect(5000)
    print(f"Your app is live at: {public_url}")

    thread = threading.Thread(target=run_flask)
    thread.start()


    Even after doing all of this, Colab gets stuck on 127.0.0.1 with extremely messy logs, and I don’t get a public URL from ngrok.

    I just to run a simple Flask app in Colab and get a public ngrok URL so I can test a chatbot UI with /handle_message.

    Has anyone been able to successfully run Flask with ngrok in Colab recently? Am I missing something about flask-ngrok or ngrok auth config in Colab?

    Continue reading...

Compartilhe esta Página