下载ngrok,ngrok下载地址为:
Download ngrokDownload ngrokhttps://download.ngrok.com/windows?tab=download下载后有个ngrok.exe 文件,通过命令行指向这个exe路径,然后启动ngrok
ngrok http 5000
安装flask
pip3 install flash
编写代码:
from flask import Flask,request,jsonify
from loguru import logger
app=Flask(__name__)
@app.route('/sms',methods=['POST'])
def receive():
sms_content=request.form.get('content')
logger.debug(f'receive:{sms_content}')
return jsonify({'code':200,'msg':'success'})
@app.route('/test',methods=['GET'])
def test():
return jsonify({'code':200,'msg':'success'})
if __name__=='__main__':
app.run(port=5000)
运行后报错:
Use "ngrok [command] --help" for more information about a command.
ERROR: authentication failed: The authtoken you specified does not look like a proper ngrok tunnel authtoken.
ERROR: Your authtoken: 2UG6Y8PFPV
ERROR: Instructions to install your authtoken are on your ngrok dashboard:
ERROR: https://dashboard.ngrok.com/get-started/your-authtoken
ERROR:
ERROR: ERR_NGROK_105
ERROR: https://ngrok.com/docs/errors/err_ngrok_105
ERROR:
从报错信息看,是ngrok缺少Authtoken
进入ngrok的官网,注册后获取authtoken:
添加authtoken
ngrok config add-authtoken 2rHjQ2xtFblXxmMe1VnyBvwtbjj_fiM5tFZoBUYyNZeGtjMw
问题解决,这样就可以通过外网穿透内网,直接在其他手机或网络访问本机对应的5000端口的flask API web了