Python 3: Does http.server support ipv6?
Starting with Python 3.8, python -m http.server
supports IPv6 (see documentation and bug report with implementation history).
To listen on all all available interfaces:
python -m http.server --bind ::
Python 3.8 is was released on 2019-10-14.
There is a patch to allow IPv6 bind in http.server
in Python 3. I tried it, finding it works on my laptop.
Please visit https://bugs.python.org/issue24209 for more info.
Or just do as following:
Add the lines after +
to the file /your/path/to/python/Lib/http/server.py
.
Please note lines without +
are the original code of server.py
.
server_address = (bind, port)
+ if ':' in bind:
+ ServerClass.address_family = socket.AF_INET6
+
HandlerClass.protocal_version = protocol
httpd = ServerClass(server_address, HandlerClass)
Then try:
python -m http.server -b *your-ipv6-addr* *your-port*
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()