A
A
Asya2021-08-18 23:51:33
Flask
Asya, 2021-08-18 23:51:33

How to transfer a flask application from localhost to another domain?

the application works locally, but when I change to another host,
app.run(host='my_website.com', port=1234)

then an error is thrown:
* Serving Flask app 'app' (lazy loading)
 * Environment: production
   WARNING: This is a development server. Do not use it in a production deployment.
   Use a production WSGI server instead.
 * Debug mode: off
Traceback (most recent call last):
  File "run.py", line 48, in <module>
    app.run(host='my_website.com', port=1234)
  File "/usr/local/lib/python3.8/dist-packages/flask/app.py", line 922, in run
    run_simple(t.cast(str, host), port, self, **options)
  File "/usr/local/lib/python3.8/dist-packages/werkzeug/serving.py", line 1008, in run_simple
    inner()
  File "/usr/local/lib/python3.8/dist-packages/werkzeug/serving.py", line 948, in inner
    srv = make_server(
  File "/usr/local/lib/python3.8/dist-packages/werkzeug/serving.py", line 780, in make_server
    return ThreadedWSGIServer(
  File "/usr/local/lib/python3.8/dist-packages/werkzeug/serving.py", line 686, in __init__
    super().__init__(server_address, handler)  # type: ignore
  File "/usr/lib/python3.8/socketserver.py", line 452, in __init__
    self.server_bind()
  File "/usr/lib/python3.8/http/server.py", line 138, in server_bind
    socketserver.TCPServer.server_bind(self)
  File "/usr/lib/python3.8/socketserver.py", line 466, in server_bind
    self.socket.bind(self.server_address)
OSError: [Errno 99] Cannot assign requested address

OSError: [Errno 99] Cannot assign requested address

how do I bind the application to my new host?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Pankov, 2021-08-19
@trapwalker

Just in case, let me remind you that if you want to place your application behind a domain, you need to:
- buy a domain from a registrar (sorry, but judging by the question, it’s not obvious that you did this),
- place your application on a machine with a white IP (order it from your provider or rent a virtual machine from some hoster.You can still tinker with dyndns, but this is a more complicated way)
- register the ip of your machine from a domain hoster by adding an A-record behind your domain.
- on your machine with a white ip, run the application, for example, on port 80 (if ssl is not needed) and make sure that the firewall does not close it.
However, if you publish the flask directly like this, nothing good will come of it.
Basically, from now on, your application will be ported to the outside and accessible through the domain.
But often, in addition to the application, you need to distribute static and wrap traffic in ssl` (for https). To do this, nginx or another proxy web server is also launched on the machine. Through it, you can distribute flask via uwsgi.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question