I'm Getting Ngrok Error 6022 after doing everything properly

37.9k views Asked by At

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

5

There are 5 answers

1
Vortekus On

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

0
Pasindu Ranasinghe On

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()

1
Programmer On

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

0
Carmine Tambascia On

A bit more general as is not very clear from documentation ERR_NGROK_6022 about such error or similar error even when tunneling connection is stablished(ERR_NGROK_8012)

This error in general happens even if you have your authtoken under ngrok.yml but are running your tunneling under your application(my case is simply a jsonserver) folder.

Simply solution is to run your tunneling, under the same folder where indeed this ngrok.yml file is, or in your script to point to use the authtoken.

So in ubuntu 18.04, a standard location for install of ngrok is ~/snap/ngrok/79/.config(version may change and I assume the installation is via snap).

there run:

ngrok http yourPort (for jsonserver default is 3000)

Hope this may help someone

0
aminator On

For me configuring the auth token in the ngrok.yml was not working.

But running the ngrok command with the auth token works: ngrok http <port_here> --authtoken <my_token_here>