To return a binary response from a HTTP server in Python, you can set the Content-Type
header to application/octet-stream
which indicates that the response is in binary format, and then return the binary data as the content of the response.
Here's an example using the built-in http.server
module:
main.py502 chars17 lines
This starts an HTTP server on port 8000 that returns dummy binary data (b'\x00\x01\x02\x03'
) for every GET request.
gistlibby LogSnag