详情可以引用我的图片。 这是我在 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()
获取此输出:
* 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 -
当我点击 ngrok 链接时,即 http://de4b-35-230-126-117.ngrok.io这个给了我这个。
ERR_NGROK_6022
Before you can serve HTML content, you must sign up for a free ngrok account and install your
authtoken.
所以谁能告诉我我做错了什么?因为我也在 colab 中安装了 ngrok 并安装了 auth token 但仍然出现此错误。
最佳答案
我遇到了同样的问题,ngrok 已更新到 v3,您可以使用 pyngrok 或更新您的代码
解决方案 1: 删除 curl 命令,并改为添加: !pip 安装 pyngrok==4.1.1
解决方案 2: 按照新文档更新绑定(bind) authtoken 的方法 https://ngrok.com/docs/guides/upgrade-v2-v3
关于python - 正确完成所有操作后出现 Ngrok 错误 6022,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71900716/