简体   繁体   中英

gevent flask in python

I have a code..and a domain name, I like to use this code to display 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()

It shows 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.. Thanks for helping

Take a look at gevent 's baseserver.py at their github repo .

The address either needs to be a tuple containing the address and the port, or a string with a ":" separating the address from the port. Ie, these would be both valid

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

or

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM