0

I'm trying to bind WSGIServer to a IPv6 loopback address:

import socket
import gevent
from gevent.pywsgi import WSGIServer

addrs = socket.getaddrinfo('::1', 8000, socket.AF_INET6, 0, socket.SOL_TCP)
bind_spec = addrs[0][-1]

listener = socket.socket(socket.AF_INET6, socket.SOCK_STREAM)
listener.bind(bind_spec)

server = WSGIServer(
    listener,
    lambda a,b:'asd'
)

server.serve_forever()

But this only yields

error: [Errno 22] Invalid argument

in

File "/usr/local/lib/python2.7/dist-packages/gevent/server.py", line 122, in _do_accept
  client_socket, address = self.socket.accept()

I've tried to use gevent monkeypatcher, that didn't help. Importing gevent AFTER socket creation didn't help either.

IPv6 is enabled on my system. If I replace server construction with plain accept(), socket binds successfully and accepts connections.

listener.listen(5)
listener.accept()
Eugene Pankov
  • 856
  • 1
  • 15
  • 30

1 Answers1

0

I'm so stupid... GEvent doesn't invoke listen() on the provided socket, so I had to call it myself before creating the server.

Eugene Pankov
  • 856
  • 1
  • 15
  • 30