Python – Gevent flask in python

Gevent flask in python… here is a solution to the problem.

Gevent flask in python

I have a code: And a domain name, me
Love to use this code to appear in my domain name

from flask import Flask
import gevent.wsgi

app=Flask(__name__)

@app.route('/')
def index():
        return "hello world"
app_server = gevent.wsgi.WSGIServer(('x.y.z.a'), app)
app_server.serve_forever()

Display error:

Traceback (most recent call last):
  File "p.py", line 10, in <module>
    app_server = gevent.wsgi.WSGIServer(('184.171.170.27'), app)
  File "/usr/lib/python2.7/dist-packages/gevent/pywsgi.py", line 605, in __init__
    StreamServer.__init__(self, listener, backlog=backlog, spawn=spawn, **ssl_args)
  File "/usr/lib/python2.7/dist-packages/gevent/server.py", line 48, in __init__
    BaseServer.__init__(self, listener, handle=handle, spawn=spawn)
  File "/usr/lib/python2.7/dist-packages/gevent/baseserver.py", line 61, in __init__
    self.set_listener(listener)
  File "/usr/lib/python2.7/dist-packages/gevent/server.py", line 70, in set_listener
    BaseServer.set_listener(self, listener)
  File "/usr/lib/python2.7/dist-packages/gevent/baseserver.py", line 80, in set_listener
    self.family, self.address = parse_address(listener)
  File "/usr/lib/python2.7/dist-packages/gevent/baseserver.py", line 323, in parse_address
    raise ValueError('Failed to parse address %r: %s' % (address, sys.exc_info()[1]))
ValueError: Failed to parse address '184.171.170.27': invalid literal 
for int() with base 10: '184.171.170.27'

What to do.. Thank you for your help

Solution

Check out gevent's baseserver.py in their github repo .

The address needs to be a tuple containing the address and port, or a string separating the address from the port with ":". That is, these are valid

app_server = gevent.wsgi.WSGIServer('x.y.z.a:51515', app)

or

app_server = gevent.wsgi.WSGIServer(('x.y.z.a', 51515), app)

Related Problems and Solutions