Shu*_*ule 10 webserver ipv6 python-3.x
难道http.server(http是一个Python 3.x的模块),支持IPv6的?例如,使用此命令行代码(启动Web服务器):
python -m http.server [port]
Run Code Online (Sandbox Code Playgroud)
是的,它确实.当定义你的服务器,像这样做,因为看到这里.
import socket
from http.server import HTTPServer
class HTTPServerV6(HTTPServer):
address_family = socket.AF_INET6
Run Code Online (Sandbox Code Playgroud)
然后像这样听:
server = HTTPServerV6(('::', 8080), MyHandler)
server.serve_forever()
Run Code Online (Sandbox Code Playgroud)
小智 6
http.server在Python 3中有一个允许IPv6绑定的补丁.我试过它,发现它可以在我的笔记本电脑上运行.有关更多信息,请访问https://bugs.python.org/issue24209.或者只需执行以下操作:
将后面的行添加+到文件中/your/path/to/python/Lib/http/server.py.请注意没有+的行是原始代码server.py.
server_address = (bind, port)
+ if ':' in bind:
+ ServerClass.address_family = socket.AF_INET6
+
HandlerClass.protocal_version = protocol
httpd = ServerClass(server_address, HandlerClass)
Run Code Online (Sandbox Code Playgroud)
然后尝试:
python -m http.server -b *your-ipv6-addr* *your-port*
Run Code Online (Sandbox Code Playgroud)
从Python 3.8开始,python -m http.server支持IPv6(请参阅文档和带有实现历史记录的错误报告)。
要监听所有可用接口:
python -m http.server --bind ::
Run Code Online (Sandbox Code Playgroud)
Python 3.8已于2019-10-14发行。
| 归档时间: |
|
| 查看次数: |
5770 次 |
| 最近记录: |