Python3搭建http伺服器

2021-10-02 16:36:21 字數 1164 閱讀 7932

在本機搭建web伺服器其實也有更簡單的方法,可以利用iis功能。可以自行搜尋本機iis搭建web伺服器。不用寫**,windows自帶的web伺服器功能。

python2提供了basehttpserver模組,不過在py3把它合併到了http.server中。

老教材用basehttpserver你可以直接用http.server代替即可。

這裡利用http.server搭建最簡單的web伺服器:

# 標識傳遞資料型別

self.send_header(

'content-type'

,'text/html'

) self.end_headers(

) self.wfile.write(

'這裡用來傳資料'

)# 下面的形式可以用來傳html檔案

# with open('d:\\python網路程式設計基礎\\python**\\http.html','rb') as t:

# print('輸出了')

)然後可以用瀏覽器,訪問localhost,預設的是80埠。

一般80是http,443是https,這裡你也可以用別的埠。

Python3開啟自帶http服務

使用web服務 python中自帶了簡單的伺服器程式,能較容易地開啟服務。在python3中將原來的 httpserver命令改為了http.server,使用方法如下 1.cd www目錄 2.python m http.server開啟成功,則會輸出 serving http on 0.0.0....

python3搭建web伺服器

傳送http請求 print html 伺服器 伺服器內部錯誤 這裡要處理兩個異常,乙個是讀入路徑時可能出現的異常,乙個是讀入路徑後若不是檔案,要作為異常處理 try 獲取檔案路徑 full path os.getcwd self.path 如果路徑不存在 if not os.path.exists...

python3呼叫http介面

最近在寫python呼叫介面的服務,寫了乙個呼叫介面的函式,如下 param inputdata 單個樣本的輸入引數,是json格式的資料 return 單個樣本的探真查詢變數結果資料 呼叫介面 介面有正確的資料才讀入,否則為空 if res code 0000 res data json.load...