Python 3: Does http.server support ipv6?
There is a patch that allows IPv6 to bind http.server
in Python 3. I tried it, finding that it works on my laptop. For more information visit https://bugs.python.org/issue24209 . Or just follow these steps:
Add the lines after +
to the file /your/path/to/python/Lib/http/server.py
. Please note that lines without +
are source code 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*
source to share
Since Python 3.8, python -m http.server
supports IPv6 (see documentation and bug report for implementation history ).
To listen to all available interfaces:
python -m http.server --bind ::
Python 3.8 released on 2019-10-14 .
source to share
Oliver Bock's version of Python 3 (up to 3.8) looks like this:
myserver.py:
from http.server import HTTPServer
from http.server import SimpleHTTPRequestHandler
import socket
class HTTPServerV6(HTTPServer):
address_family = socket.AF_INET6
server = HTTPServerV6(('::', 8080), SimpleHTTPRequestHandler)
server.serve_forever()
Modifying your internal Python 3 files like Edward Zhang looks pretty extreme.
source to share