python server搭建


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.報錯:

 

 

 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 -

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM