import os
import time
import traceback
import SocketServer
from BaseHTTPServer import BaseHTTPRequestHandler


def serve_file(filename, address="", port=45114):
    class FileHandler(BaseHTTPRequestHandler):
        def do_GET(self):
            try:
                f = open(filename, "rb")
                st = os.fstat(f.fileno())
                length = st.st_size
                self.send_response(200)
                self.send_header("Content-type", "video/mp4")
                self.send_header("Content-Length", length)
                self.send_header("Accept-Ranges", "bytes")
                self.send_header(
                    "Last-Modified",
                    time.strftime(
                        "%a %d %b %Y %H:%M:%S GMT",
                        time.localtime(os.path.getmtime(filename))
                    )
                )
                self.end_headers()
                while True:
                    data = f.read(100 * 1024)
                    if not data:
                        break
                    self.wfile.write(data)
            except:
                traceback.print_exc()
            f.close()

    httpd = SocketServer.TCPServer((address, port), FileHandler)
    httpd.serve_forever()
    httpd.server_close()

import os
import time
import traceback
try:
    import SocketServer
except ImportError:
    import socketserver as SocketServer
try:
    from BaseHTTPServer import BaseHTTPRequestHandler
except ImportError:
    from http.server import BaseHTTPRequestHandler


def serve_file(filename, address="", port=45114):
    class FileHandler(BaseHTTPRequestHandler):
        def do_GET(self):
            try:
                f = open(filename, "rb")
                st = os.fstat(f.fileno())
                length = st.st_size
                self.send_response(200)
                self.send_header("Content-type", "video/mp4")
                self.send_header("Content-Length", length)
                self.send_header("Accept-Ranges", "bytes")
                self.send_header(
                    "Last-Modified",
                    time.strftime(
                        "%a %d %b %Y %H:%M:%S GMT",
                        time.localtime(os.path.getmtime(filename))
                    )
                )
                self.end_headers()
                while True:
                    data = f.read(100 * 1024)
                    if not data:
                        break
                    self.wfile.write(data)
            except:
                traceback.print_exc()
            f.close()

    httpd = SocketServer.TCPServer((address, port), FileHandler)
    httpd.serve_forever()
    httpd.server_close()

Add python3 compatible imports