Simple Webserver problem

Colin Brown cbrown at metservice.com
Thu Oct 30 18:54:57 EST 2003


I am attempting to construct a simple webserver for browsing
text files with arbitrary file extensions based on the standard
Python library modules. Not all files are being returned as text.
[Python 2.3.2, Platform: Win2K, Browser IE6]. Code as below.

Any assistance appreciated.

Colin Brown
PyNZ
-------------------------------------------
#  Usage: Browse to: http://localhost:8090
import os, sys, BaseHTTPServer, SimpleHTTPServer

PORT = 8090
DEFPATH = r'C:\logs'

class TextHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
    def guess_type(self, path):
        return 'text/plain'

# run an HTTP Server on PORT based at DEFPATH
sys.argv = ['',PORT]
os.chdir(DEFPATH)
BaseHTTPServer.test(TextHandler,BaseHTTPServer.HTTPServer)







More information about the Python-list mailing list