Skip to main content
 首页 » 编程设计

python之通过 VPN 连接到 Flask 应用程序

2024年10月01日8shanyou

我是 Flask 的新手,如果问题听起来微不足道,请不要介意。 我有一个 Flask 应用程序(不是我写的),当我直接连接到网络时,它在本地机器和远程机器上都能正常工作。

但是当我通过 VPN 连接到应用程序时,它不起作用。我能够在那台机器上 ssh 以及访问在同一台机器上运行的其他服务器。是物理机不是VM

app = Flask(__name__) 
 
def loadAppVariables(): 
      mc = pylibmc.Client(["127.0.0.1"], binary=True, 
      behaviors={"tcp_nodelay": True, 
      "ketama": True}); 
      app.mc=mc 
 
def initApp(): 
    app.fNet= {some object } 
    mc = pylibmc.Client(["127.0.0.1"], binary=True, 
    behaviors={"tcp_nodelay": True, 
    "ketama": True}); 
    app.mc=mc; 
 
@app.route('/classify', methods=['POST']) 
def classify(): 
        # We will save the file to disk for possible data collection. 
        imagefile = request.files['imagefile'] 
        processImageFile(imagefile) 
 
@app.route('/') 
def index(): 
    return render_template('cindex.html', has_result=False) 
 
@app.before_request 
def before_request(): 
    loadAppVariables() 
 
@app.teardown_request 
def teardown_request(exception): 
    storeAppVariables() 
 
if __name__ == '__main__': 
    initApp(); 
    app.run(debug=False,host='0.0.0.0') 

我正在运行最新的 Flask 版本和 python 2.7。任何人都可以建议这里可能有什么问题吗?

请您参考如下方法:

您似乎想通过另一个网络访问本地启用的 flask 。 0.0.0.0 ip是从不同的机器连接到flask,但是在同一个网络范围内。因此,如果您的 IP 不在同一范围内,则会失败。

如果你想从互联网访问你的网页,你应该考虑deploy你的网络应用程序。