第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

我可以獲取flask_ngrok或py-ngrok生成的IP地址或域名并將其返回到

我可以獲取flask_ngrok或py-ngrok生成的IP地址或域名并將其返回到

冉冉說 2023-12-20 16:05:29
我正在嘗試獲取部署后 Flask_ngrok 或 py-ngrok 生成的域名或 IP 地址。我想將flask_app部署到本地主機并在主頁上獲取新的IP地址或域名。IE:如果我訪問127.0.0.1/我希望它返回類似的內容 You can now log in through https://aaf8447ee878.ngrok.io/我嘗試檢查目錄并閱讀一些幫助,但我仍然無法得到它。預先感謝?
查看完整描述

3 回答

?
茅侃侃

TA貢獻1842條經驗 獲得超21個贊

添加


import atexit

import json

import os

import platform

import shutil

import subprocess

import tempfile

import time

import zipfile

from pathlib import Path

from threading import Timer


import requests



def _run_ngrok():

    ngrok_path = str(Path(tempfile.gettempdir(), "ngrok"))

    _download_ngrok(ngrok_path)

    system = platform.system()

    if system == "Darwin":

        command = "ngrok"

    elif system == "Windows":

        command = "ngrok.exe"

    elif system == "Linux":

        command = "ngrok"

    else:

        raise Exception(f"{system} is not supported")

    executable = str(Path(ngrok_path, command))

    os.chmod(executable, 777)


    ngrok = subprocess.Popen([executable, 'http', '5000'])

    atexit.register(ngrok.terminate)

    localhost_url = "http://localhost:4040/api/tunnels"  # Url with tunnel details

    time.sleep(1)

    tunnel_url = requests.get(localhost_url).text  # Get the tunnel information

    j = json.loads(tunnel_url)


    tunnel_url = j['tunnels'][0]['public_url']  # Do the parsing of the get

    tunnel_url = tunnel_url.replace("https", "http")

    return tunnel_url



def _download_ngrok(ngrok_path):

    if Path(ngrok_path).exists():

        return

    system = platform.system()

    if system == "Darwin":

        url = "https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-darwin-amd64.zip"

    elif system == "Windows":

        url = "https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-windows-amd64.zip"

    elif system == "Linux":

        url = "https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-linux-amd64.zip"

    else:

        raise Exception(f"{system} is not supported")

    download_path = _download_file(url)

    with zipfile.ZipFile(download_path, "r") as zip_ref:

        zip_ref.extractall(ngrok_path)



def _download_file(url):

    local_filename = url.split('/')[-1]

    r = requests.get(url, stream=True)

    download_path = str(Path(tempfile.gettempdir(), local_filename))

    with open(download_path, 'wb') as f:

        shutil.copyfileobj(r.raw, f)

    return download_path


def start_ngrok():

    global ngrok_address

    ngrok_address = _run_ngrok()

    print(f" * Running on {ngrok_address}")

    print(f" * Traffic stats available on http://127.0.0.1:4040")



def run_with_ngrok(app):

    """

    The provided Flask app will be securely exposed to the public internet via ngrok when run,

    and the its ngrok address will be printed to stdout

    :param app: a Flask application object

    :return: None

    """

    old_run = app.run


    def new_run():

        thread = Timer(1, start_ngrok)

        thread.setDaemon(True)

        thread.start()

        old_run()

    app.run = new_run


####################

不要在name == ' main '之前導入flask_ngrok添加此函數


def ngrok_url():

    global tunnel_url

    while True:

        try:

            print(ngrok_address)

        except Exception as e:

            print(e)

并在 app.run() 之前放置


thread = Timer(1, ngrok_url)

thread.setDaemon(True)

thread.start()

并運行警告:如果您不希望在 ngrok url 函數中將 print 替換為您想要對 url 執(zhí)行的任何操作,這將使您的代碼編輯器/或終端崩潰


查看完整回答
反對 回復 2023-12-20
?
慕勒3428872

TA貢獻1848條經驗 獲得超6個贊

我發(fā)現最簡單的方法是在用戶訪問該網站時復制網址。你可以通過...來做到這一點


@app.before_request

def before_request():

    global url

    url = request.url

    # url = url.replace('http://', 'https://', 1)

    url = url.split('.ngrok.io')[0]

    url += '.ngrok.io'


查看完整回答
反對 回復 2023-12-20
?
有只小跳蛙

TA貢獻1824條經驗 獲得超8個贊

你不需要那個


global tunnel_url

def ngrok_url():

    while True:

        try:

            print(ngrok_address)

        except Exception as e:

                print(e)

您也可以在導入集之后 刪除name == ' main '之前的線程部分ngrok_address = '' ,然后您可以在代碼中的任何位置訪問 ngrok_address


查看完整回答
反對 回復 2023-12-20
  • 3 回答
  • 0 關注
  • 213 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號