1

I tried to launche Flask in hosting using:

if __name__ == "__main__":
    app.run('0.0.0.0', 8000)

But hoster has 8080 port as closed, it is possible to run Flask with default port 80?

I tried it gives me this error:

Use a production WSGI server instead.                                                                                                                                                                     
 * Debug mode: off                                                                                                                                                                                           
Traceback (most recent call last):                                                                                                                                                                           
  File "__init__.py", line 461, in <module>                                                                                                                                                                  
    app.run('0.0.0.0', 80)                                                                                                                                                                                   
  File "/home/o/oliwin4/project/public_html/myenv/local/lib/python2.7/site-packages/flask/app.py", line 943, in run                                                                                          
    run_simple(host, port, self, **options)                                                                                                                                                                  
  File "/home/o/oliwin4/project/public_html/myenv/local/lib/python2.7/site-packages/werkzeug/serving.py", line 814, in run_simple                                                                            
    inner()                                                                                                                                                                                                  
  File "/home/o/oliwin4/project/public_html/myenv/local/lib/python2.7/site-packages/werkzeug/serving.py", line 774, in inner                                                                                 
    fd=fd)                                                                                                                                                                                                   
  File "/home/o/oliwin4/project/public_html/myenv/local/lib/python2.7/site-packages/werkzeug/serving.py", line 660, in make_server                                                                           
    passthrough_errors, ssl_context, fd=fd)                                                                                                                                                                  
  File "/home/o/oliwin4/project/public_html/myenv/local/lib/python2.7/site-packages/werkzeug/serving.py", line 577, in __init__                                                                              
    self.address_family), handler)                                                                                                                                                                           
  File "/usr/lib/python2.7/SocketServer.py", line 419, in __init__                                                                                                                                           
    self.server_bind()                                                                                                                                                                                       
  File "/usr/lib/python2.7/BaseHTTPServer.py", line 108, in server_bind                                                                                                                                      
    SocketServer.TCPServer.server_bind(self)                                                                                                                                                                 
  File "/usr/lib/python2.7/SocketServer.py", line 430, in server_bind                                                                                                                                        
    self.socket.bind(self.server_address)                                                                                                                                                                    
  File "/usr/lib/python2.7/socket.py", line 224, in meth                                                                                                                                                     
    return getattr(self._sock,name)(*args)                                                                                                                                                                   
socket.error: [Errno 1] Operation not permitted   

So, hoster said tht 80 port is open.

POV
  • 11,293
  • 34
  • 107
  • 201

1 Answers1

1

The Flask documentation states that:

While lightweight and easy to use, Flask’s built-in server is not suitable for production as it doesn’t scale well. Some of the options available for properly running Flask in production are documented here.

The documentation also states several methods of using WSGI servers to deploy your web application. WSGI (Web Server Gateway Interface) is a standard that forwards requests from web servers to web applications written in Python. You'll want to use a WSGI server to run your website on your host, since it sounds like you're trying to deploy a Flask app to a production setting.

To answer your original question, the Flask library intentionally throws an error when you try to run it on port 80, because they specifically say that you should not use Flask's built-in server for production use. That's this part of your stacktrace:

Use a production WSGI server instead.                                                                                                                                                                     
* Debug mode: off    

and

socket.error: [Errno 1] Operation not permitted   

For the lazy, or if the above link goes dead, here is an example using Gunicorn (copied directly from the above documentation link)

Gunicorn

Gunicorn ‘Green Unicorn’ is a WSGI HTTP Server for UNIX. It’s a pre-fork worker model ported from Ruby’s Unicorn project. It supports both eventlet and greenlet. Running a Flask application on this server is quite simple:

gunicorn myproject:app

Gunicorn provides many command-line options – see gunicorn -h. For example, to run a Flask application with 4 worker processes (-w 4) binding to localhost port 4000 (-b 127.0.0.1:4000):

gunicorn -w 4 -b 127.0.0.1:4000 myproject:app

brunston
  • 1,244
  • 1
  • 10
  • 18