Dec-02-2021, 11:43 PM
Python 3.9. Local http.server 127.0.0.1:9001. I need to take an image, then save it to disk. The program that sends the image sends it with a POST request with the Multipart/form-data type, the image itself is jpg. At the moment there is such a code:
from http.server import BaseHTTPRequestHandler, HTTPServer class MyServer(BaseHTTPRequestHandler): def _set_headers(self): self.send_response(200) self.send_header('Content-type', 'application/json') self.end_headers() def do_POST(self): content_length = int(self.headers['Content-Length']) post_data = self.rfile.read(content_length) self.wfile.write(post_data .encode('utf-8')) webServer = HTTPServer(("", 9001), MyServer) webServer.serve_forever()