from http.server import HTTPServer, BaseHTTPRequestHandler class SimpleHTTPRequestHandler(BaseHTTPRequestHandler): def do_GET(self): if (self.path == "/"): self.send_response(200) self.send_header('Content-type','text/html') self.send_header('Access-Control-Allow-Origin','*') self.end_headers() self.wfile.write("我是首頁".encode()) #轉成二進位 if (self.path == "/get_info"): self.send_response(200) self.send_header('Content-type','application/json') self.send_header('Access-Control-Allow-Origin','*') self.end_headers() self.wfile.write("資訊頁測試.encode()) #轉成二進位 httpd = HTTPServer(('0.0.0.0', 80), SimpleHTTPRequestHandler) httpd.serve_forever()
Python3建立簡單的http server
因為需要測試Web API,所以利用python 3來建立一個簡單的http server,並傳回字串,程式如下,配合Docker還真的蠻方便的。
-
Windows7 / Windows8 kill process Linux下要刪除某個程序通常會使用 ps 配合 kill 來刪除程序。 例如:ps -ef |grep [PROCESS NAME] kill -9 [PID] 在Windows下,通常是...
-
利用Win 10的工作排程器來設定每日自動執行的批次檔,單獨執行批次檔沒問題,但是放在排程上就是無法執行。 後來試了幾種網路上提供的方式,其注意的事項如下: 1、在「安全性選項」選擇「只有使用者登入時才執行」並取消「以最高權限執行」。 2、在「設定」中選擇「Win...
-
其實預設都會幫我們安裝pip這個管理套件,但是我在安裝完python 3.7後卻無法使用pip來安裝套件。 查詢是否已經有安裝pip: C:\> python -m pip --version pip 20.0.2 from C:\Python37\lib\si...