Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python 3: Does http.server support ipv6?

Tags:

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] 
like image 313
Brōtsyorfuzthrāx Avatar asked Sep 12 '14 22:09

Brōtsyorfuzthrāx


People also ask

What does python3 HTTP server do?

Python 3 http server is a built-in Python module that provides typical GET and HEAD request handlers. Any directory on our system can be turned into a web server with this module.

Does Python have HTTP server?

You can run python http server on any port, default port is 8000. Try to use port number greater than 1024 to avoid conflicts. Then open your favourite browser and type localhost:9000 .

Is Python HTTP server safe?

Warning http. server is not recommended for production. It only implements basic security checks. It doesn't state what security vulnerabilities the server is exposed to.


2 Answers

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.

like image 82
sebas Avatar answered Sep 21 '22 18:09

sebas


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() 
like image 37
Oliver Bock Avatar answered Sep 17 '22 18:09

Oliver Bock