当前位置:当前位置:首页 >应用开发 >Python 中的 HTTP 服务器 正文

Python 中的 HTTP 服务器

[应用开发] 时间:2025-11-05 07:21:02 来源:益强IT技术网 作者:IT科技 点击:13次
Python 中的 HTTP 服务器
复制# 用WSGI应用形式编写的服务简单HTTP服务。免费信息发布网  #!/usr/bin/env python3  # A simple HTTP service built directly against the low-level WSGI spec.  from pprint import pformat  from wsgiref.simple_server import make_server  def app(environ,服务 start_response):      headers = {Content-Type: text/plain; charset=utf-8}      start_response(200 OK, list(headers.items()))      yield Here is the WSGI environment:  .encode(utf-8)      yield pformat(environ).encode(utf-8)  if __name__ == __main__:      httpd = make_server(, 8000, app)      host, port = httpd.socket.getsockname()      print(Serving on, host, port, port)      httpd.serve_forever()  1.2.3.4.5.6.7.8.9.10.11.12.13.14.15.16.17.18.19.20.源码库

(责任编辑:数据库)

    相关内容
    精彩推荐
    热门点击
    友情链接