Deploying a Flask Web Application: Access from Remote Server

Viewed 765

I am building a small web app with Flask so that someone else can use my script from their device (in network) without installing the attendant modules. I can get the app to run on my localhost but am having trouble getting it to be available to other devices in network.

I'm using Flask's in-built platform so I am using app.run(host="0.0.0.0"). I've tried enabling/disabling the debug parameter. I've tried adding the port parameter as 5000, although it already seems to be running on that port. I've had the other person go to http://my_ip_address:5000 as well as http://0.0.0.0:5000 (not sure which one they should be using).

Below is a segment of my code, with the actual app classes and methods not included:

from flask import Flask, render_template, request
app = Flask(__name__)

@app.route('/')
def command_outputs():
    return render_template("info.html")

@app.route('/result',methods = ['POST', 'GET'])
def result():
   if request.method == 'POST':
       result = request.form
       f=request.files["File"]
       f.save(f.filename)
       f.stream.seek(0)
       finder=OutputFinder(result["Device"], f, result["Username"], result["Password"])
       finder.findOutput()
       lines=finder.result.split("\n")
       return "<br/>".join(lines)

if __name__ == '__main__':
   app.run(host='0.0.0.0', debug=False)

When I run the script (I am using PyCharm) and enter http://0.0.0.0:5000 into the browser, I get an "Unknown Host" error. When I enter the localhost or my device's IP address, I get a 404 not found error, and 127.0.0.1 - - [26/Jun/2019 15:03:42] "GET / HTTP/1.1" 404 appears in the terminal.

When the other person opens it with http://0.0.0.0:5000, they get the same error I do. When they run it using my IP address, they get a "site cannot be reached" page.

I'm pretty sure I'm just putting the wrong stuff into the URL. Also, the error messages are inconsistent sometimes. I will run the exact same script and get differing error messages, but the ones mentioned above are the most common.

EDIT: It is working on my own computer when I use my IP address in the url, but it is not working on the other person's computer using my IP address.

0 Answers
Related