http 传输文件

服务器端代码

import http.server
import socketserver

PORT = 8000

Handler = http.server.SimpleHTTPRequestHandler

with socketserver.TCPServer(("192.168.120.121", PORT), Handler) as httpd:
    print("Serving at port", PORT)
    httpd.serve_forever()
#



客户端代码

url_dir = 'http://192.168.120.121:8000/model/'
file_list = ["best_fold0_kflod.cbm","best_fold0_time_split.cbm","device_encode.json","device_latitude_longitude.json",
             "label_encoder_2.pkl",'label_encoder_3.pkl','label_encoder_4.pkl',"US_info_ep500.csv"]

for file_name in file_list:
    url = url_dir + file_name
    response = requests.get(url)

    with open(file_name, 'wb') as f:
        f.write(response.content)

 

posted @ 2024-09-18 16:39  刘文华  阅读(7)  评论(0编辑  收藏  举报