Flask-ngrok with google collab, connection error. How Fix?

160 Views Asked by At

I'm trying to implement a simple graphic interface using Google Colab and Flask Ngrok. However, I'm encountering an issue with the connection. Here's the relevant part of my code:

   !pip install flask-ngrok
   !pip install pyngrok
   !ngrok authtoken <your_authtoken_here>
    from flask import Flask
    from flask_ngrok import run_with_ngrok

    app = Flask(__name__)
    run_with_ngrok(app)  # Start ngrok when app is run

    @app.route("/")
    def hello():
        return "Hello World!"

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

When I run the code, I get the following error:

ConnectionRefusedError: [Errno 111] Connection refused This error occurs when the following line of code is executed: ` Ecco una versione della tua domanda che potrebbe essere accettata su Stack Overflow:

Title: Unable to establish connection with Flask Ngrok: ConnectionRefusedError

Body:

Hi,

I'm trying to implement a simple graphic interface using Google Colab and Flask Ngrok. However, I'm encountering an issue with the connection. Here's the relevant part of my code:

python Copy code !pip install flask-ngrok !pip install pyngrok !ngrok authtoken <your_authtoken_here> python Copy code from flask import Flask from flask_ngrok import run_with_ngrok

app = Flask(name) run_with_ngrok(app) # Start ngrok when app is run

@app.route("/") def hello(): return "Hello World!"

if name == 'main': app.run()

When I run the code, I get the following error:

ConnectionRefusedError: [Errno 111] Connection refused This error occurs when the following line of code is executed:

tunnel_url = requests.get(localhost_url).text

All the errors is: requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=4040): Max retries exceeded with url: /api/tunnels (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7eb8bc5e9300>: Failed to establish a new connection: [Errno 111] Connection refused'))

0

There are 0 best solutions below