Search code examples
python-3.xwebserveripv6

Python 3: Does http.server support ipv6?


Does http.server (http being a Python 3.x module) support ipv6? For instance, using this command-line code (which starts a webserver):

python -m http.server [port]

Solution

  • Yes, it does. When defining your server, do it like this, as seen here.

    import socket
    from http.server import HTTPServer
    
    class HTTPServerV6(HTTPServer):
        address_family = socket.AF_INET6
    

    and then listen like this:

    server = HTTPServerV6(('::', 8080), MyHandler)
    server.serve_forever()