19

The question in short

How do you run a simple Flask-based website visible to the internet, from a host PC which is accessing the internet from a wireless router?

Question details

I would like to make a flask application visible to the internet, as per Quickstart Guide.

If I launch the simple Flask app below, it becomes accessible from a computer on the same network as the host pc, but not from a device connected through the internet through another network.

The problem is similar to the one discussed here and here, with the added element that running from a home pc seems to suggest that external connections point to the xx port of the router, not to the xx port of the host pc, as is suggested in the comments in this post.

What I did

Referencing the code below, here's what I did:

  • Checked my IP address in Control Panel
  • disabled all network protection in the antivirus
  • run `ipconfig /all', being on a windows machine
  • finally opened a browser in a device connected to another network and pointed it to the appropriate IP:port address

The result is that "The webpage is not available".

Has anybody encountered the same problem? Is this a router issue?

Reference Flask app

from flask import Flask
app = Flask(__name__)

@app.route('/')
def hello_world():
    return 'Hello World!'

if __name__ == '__main__':
    app.run(host= '0.0.0.0', port=9000, debug=False)
Community
  • 1
  • 1
Pythonic
  • 2,091
  • 3
  • 21
  • 34
  • 2
    Routers are specifically made to prevent this kind of behavior and keep your home connection protected from the outside world. You might be able to find a workaround, but you shouldn't. – Slater Victoroff May 14 '15 at 15:34
  • 2
    Need to set up the router to forward requests to port 9000 of the IP of the computer that is running the flask app – reptilicus May 14 '15 at 15:35
  • Why would you want to do this? I would recommend setting up a site on Heroku for something as trivial as this. – kylieCatt May 14 '15 at 15:36
  • Probably just playing around, nothing wrong with learning the hard way :) – reptilicus May 14 '15 at 15:37
  • 1
    If you're interested in learning then learning how to deploy Heroku or AWS will likely be of more use than opening up your home PC to the internet. – kylieCatt May 14 '15 at 15:47
  • 1
    Thanks for the comments. To provide some context, these are initial prototyping experiments in a move from desktop-based GUIs (mainly PyQt) to web-apps. So yes, need to learn how to deploy Heroku. Home computer was an easy environment for a number of reasons (mainly local db access, and no prior knowledge of cloud-based services) – Pythonic May 14 '15 at 16:02

1 Answers1

18

The basic setup will be to create a rule which will forward request to port 80 and/or port 443 to a destined host in your local network.

Example create NAT(address translation) and port forwarding rule to forward inbound HTTP/S requests to your local network host running your python application.

For example:

app.run(host= '192.168.0.58', port=9000, debug=False)

Your NAT rule should target 192.168.0.58 on port 9000.

Bitmap
  • 12,402
  • 16
  • 64
  • 91