'I'm Getting Ngrok Error 6022 after doing everything properly

You can refer to my images for details. This is the code I'm running on colab:

from google.colab import drive
drive.mount('/content/drive')

cd /content/drive/MyDrive/mini

!curl -s https://ngrok-agent.s3.amazonaws.com/ngrok.asc | sudo tee 
/etc/apt/trusted.gpg.d/ngrok.asc >/dev/null && echo "deb https://ngrok-agent.s3.amazonaws.com 
buster main" | sudo tee /etc/apt/sources.list.d/ngrok.list && sudo apt update && sudo apt 
install ngrok

!ngrok authtoken "I added my auth token here"

from pyngrok import ngrok
from flask_ngrok import run_with_ngrok
from flask import Flask, render_template
app = Flask(__name__)
run_with_ngrok(app)
@app.route('/')
def text():
  return f"Running Flask on Google Colab"

app.run()

Getting this output:

 * Serving Flask app "__main__" (lazy loading)
 * Environment: production
   WARNING: This is a development server. Do not use it in a production deployment.
   Use a production WSGI server instead.
 * Debug mode: off
 * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
 * Running on http://de4b-35-230-126-117.ngrok.io
 * Traffic stats available on http://127.0.0.1:4040
127.0.0.1 - - [17/Apr/2022 09:03:31] "GET / HTTP/1.1" 200 -
127.0.0.1 - - [17/Apr/2022 09:03:32] "GET /favicon.ico HTTP/1.1" 404 -

When I click on the ngrok link i.e http://de4b-35-230-126-117.ngrok.io this one it gives me this.

ERR_NGROK_6022
Before you can serve HTML content, you must sign up for a free ngrok account and install your 
authtoken.

So can anyone tell me what I'm doing wrong? Cuz I installed ngrok also and install auth token also in colab but still getting this error. So I did this each steps Executed successfully:

Still Getting This Error



Solution 1:[1]

I was having the same issue, ngrok updated to v3 and you can either use pyngrok or update your code

Solution 1: Remove the curl commands, and add this instead: !pip install pyngrok==4.1.1

Solution 2: Update your methods to bind authtoken by following the new documentation https://ngrok.com/docs/guides/upgrade-v2-v3

Solution 2:[2]

The easiest way is to install, pyngrok==4.1.1 by typing,

!pip install pyngrok==4.1.1

No " " marks when adding the auth token.
Remove the !curl.... command, It is unnecessary.

Check this out,

!pip install pyngrok==4.1.1
!pip install flask_ngrok

from google.colab import drive
drive.mount('/content/drive')

cd /content/drive/MyDrive/mini

!ngrok authtoken "Add auth token here" #Without "" marks 

from flask_ngrok import run_with_ngrok
from flask import Flask, render_template
app = Flask(__name__)
run_with_ngrok(app)
@app.route('/')
def text():
  return f"Running Flask on Google Colab"

app.run()

Solution 3:[3]

I did This it worked for me
CODE:

import os
import threading


from flask import Flask, request, render_template
from pyngrok import ngrok

os.environ["FLASK_ENV"] = "development"

app = Flask(__name__)
port = 5000

# Open a ngrok tunnel to the HTTP server
public_url = ngrok.connect(port).public_url
print(" * ngrok tunnel \"{}\" -> \"http://127.0.0.1:{}\"".format(public_url, port))

# Update any base URLs to use the public ngrok URL
app.config["BASE_URL"] = public_url

# ... Update inbound traffic via APIs to use the public-facing ngrok URL


# Define Flask routes
@app.route("/")
def index():
    return render_template('index.html')

@app.route("/add", methods=['GET','POST'])
def add():
    global name 
    if request.method == 'POST' and 'username' in request.form :
      name=request.form['text']
      print(name)
    return render_template('index.html')

# Start the Flask server in a new thread
threading.Thread(target=app.run, kwargs={"use_reloader": False}).start()

Getting the proper results now:

enter image description here

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 Pasindu Ranasinghe
Solution 3 Programmer