1.代码:

from http.server import HTTPServer, BaseHTTPRequestHandler

class Handler(BaseHTTPRequestHandler):
        """docstring fos Handler"""
        def do_sth_for_GET(self):
            self.send_response(200)
            self.send_header('Content_type','text/plain;charset=utf-8')
            self.end_header()

            self.wfile.write('Hello everyone,I am William,I am a AI server~\n'.encode())

if __name__=='__main__':
    server_address=('',9999)
    httpd=HTTPServer(server_address,Handler)
    httpd.serve_forever()

 

2.网址中输入:127.0.0.1:9999(或者localhost:9999)

 

3.报错:

python server搭建

 

 

python server搭建

 4.解决:将do_sth_for_GET改成do_GET就好了

(base) localhost:html ligaijiang$ python3 python_server.py #然后网页中输入:http://localhost:9995
127.0.0.1 - - [09/Apr/2020 11:26:16] "GET / HTTP/1.1" 200 -

 

python server搭建

 

相关文章:

  • 2021-09-01
  • 2021-12-20
  • 2021-11-25
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-06-29
  • 2021-06-24
  • 2022-12-23
  • 2021-08-01
  • 2021-10-09
  • 2021-06-25
相关资源
相似解决方案