How To Serve Any File Type With Python's Basehttprequesthandler
Consider the following example: import string,cgi,time from os import curdir, sep from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer class MyHandler(BaseHTTPRequestHand
Solution 1:
Pass binary as a parameter to open(). This:
f = open(curdir + sep + self.path, 'rb')
Instead of this:
f = open(curdir + sep + self.path)
UNIX doesn't distinguish between binary and text, but windows does. But if the script executes on UNIX, the "b" will just be ignored so you're safe.
Solution 2:
Your line would work just fine. The problem would be setting the Content-type
appropriately. You'd want to set it to application/zip
instead of text/html
.
Solution 3:
If you want to share files in a folder of any type, then you can also try typing the command
python -m SimpleHTTPServer
This will start the server at port 8000 and you can browse the files (via directory listing)
Post a Comment for "How To Serve Any File Type With Python's Basehttprequesthandler"