0

I have a two servers. Is it possible to run the flask from e.g (192.168.1.1) using host = "192.168.1.2"

i got errors

Traceback (most recent call last):
  File "app.py", line 38, in <module>
    debug=True
  File "/usr/local/lib/python2.7/site-packages/flask/app.py", line 772, in run
    run_simple(host, port, self, **options)
  File "/usr/local/lib/python2.7/site-packages/werkzeug/serving.py", line 706, in run_simple
    test_socket.bind((hostname, port))
  File "/usr/local/lib/python2.7/socket.py", line 224, in meth
    return getattr(self._sock,name)(*args)
socket.error: [Errno 99] Cannot assign requested address

here is my code. from .e.g 192.168.1.1

from flask import Flask, render_template, request, jsonify

app = Flask(__name__)


@app.route('/index')
def index():
    return render_template('index.html')

@app.route('/_add_numbers')
def add_numbers():
    a = request.args.get('a', 0, type=int)
    b = request.args.get('b', 0, type=int)
    return jsonify(result=a + b)

if __name__ == '__main__':
    app.run(
        host="192.168.1.2",
        port=int("80"),
        debug=True
    )
2
  • Show us your code so that we can localise your problem and give you an optimised solution. Commented Feb 28, 2014 at 7:32
  • Are you running this locally? Just assign a different port for it. Don't use the flask dev server on an actual server. If you want to accomplish this on an actual server, configure apache or nginx to serve your wsgi app from a certain address / domain. Commented Feb 28, 2014 at 7:36

1 Answer 1

1

This seems to be a misunderstanding on how networking works... You cannot use the IP address of another server as your own, for the same reason you cannot invite people to your neighbor's house and expect them to end up at your door.

If you want to handle web requests on both servers, you are going to need load balancing. Or, a reverse proxy that proxies requests from one server to the other.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.