我正试图让服务器走得更远,以便更好地控制/学习.当我try 用bash创建一个简单的命令时,我得到了Mimetype错误.
我一定是看错了,但我的服务器似乎让浏览器将html呈现为文本.我在浏览器中得到的html也很奇怪.
如有任何帮助,将不胜感激!
server.py个
from http.server import HTTPServer,BaseHTTPRequestHandler
HOST = "localhost"
PORT = 7800
class FeedSpeedServer(BaseHTTPRequestHandler):
def do_GET(self):
if self.path == "/":
self.path = 'index.html'
try:
self.send_header("content-type", "text/html")
self.send_header("content-type", "text/javascript")
self.send_header("content-type", "text/css")
self.end_headers()
self.file = open(self.path).read()
self.wfile.write(self.file.encode())
self.send_response(200)
except:
self.file = "file not found"
self.send_response(404)
httpd = HTTPServer((HOST, PORT), FeedSpeedServer)
print("server running...")
httpd.serve_forever()
print("server Stopped")
我的网络浏览器显示了这个.