Serve a file from Python's http.server - correct response with a file
Looks like you are setting up the headers correctly as you say. I've done what you are trying to do only with textual data (CSV). One problem with your code as shown is that you are trying to write the file object and not the actual data. You need to do a read
to actually get the binary data.
def do_GET(self): # Your header stuff here... # Open the file with open('/filepath/file.pdf', 'rb') as file: self.wfile.write(file.read()) # Read the file and send the contents
Hopefully this at least gets you a bit closer.