# Buggy code
def received_message(self, message):
    message = json.loads(message.data)
    self.logger.info("<--- {0}".format(message))
    response = None
    if message["command"] == "hello":  # Handshake
        response = {
            "command": "hello",
            "protocols": [
                "http://livereload.com/protocols/official-7",
            ],
            "serverName": "nikola-livereload",
        }
    elif message["command"] == "info":  # Someone connected
        self.logger.info("****** Browser connected: {0}".format(message.get("url")))
        self.logger.info("****** sending {0} pending messages".format(len(pending)))
        while pending:
            msg = pending.pop()
            self.logger.info("---> {0}".format(msg.data))
            self.send(msg, msg.is_binary)
    else:
        response = {
            "command": "alert",
            "message": "HEY",
        }
    if response is not None:
        response = json.dumps(response)
        self.logger.info("---> {0}".format(response))
        response = TextMessage(response)
        self.send(response, response.is_binary)


# Traceback (AssertionError)
Traceback (most recent call last):
File "/usr/lib/python3.4/wsgiref/handlers.py", line 137, in run
self.result = application(self.environ, self.start_response)
File "/home/user/.local/lib/python3.4/site-packages/nikola/plugins/command/auto/__init__.py", line 188, in __call__
return parent.serve_static(environ, start_response)
File "/home/user/.local/lib/python3.4/site-packages/nikola/plugins/command/auto/__init__.py", line 243, in serve_static
start_response(b'200 OK', [(b'Content-type', mimetype)])
File "/usr/lib/python3.4/wsgiref/handlers.py", line 226, in start_response
self.headers = self.headers_class(headers)
File "/usr/lib/python3.4/wsgiref/headers.py", line 38, in __init__
self._convert_string_type(k)
File "/usr/lib/python3.4/wsgiref/headers.py", line 46, in _convert_string_type
" of type str (got {0})".format(repr(value)))
AssertionError: Header names/values must be of type str (got b'Content-type')

# Fixed code
def received_message(self, message):
    message = json.loads(message.data.decode("utf8"))
    self.logger.info("<--- {0}".format(message))
    response = None
    if message["command"] == "hello":  # Handshake
        response = {
            "command": "hello",
            "protocols": [
                "http://livereload.com/protocols/official-7",
            ],
            "serverName": "nikola-livereload",
        }
    elif message["command"] == "info":  # Someone connected
        self.logger.info("****** Browser connected: {0}".format(message.get("url")))
        self.logger.info("****** sending {0} pending messages".format(len(pending)))
        while pending:
            msg = pending.pop()
            self.logger.info("---> {0}".format(msg.data))
            self.send(msg, msg.is_binary)
    else:
        response = {
            "command": "alert",
            "message": "HEY",
        }
    if response is not None:
        response = json.dumps(response)
        self.logger.info("---> {0}".format(response))
        response = TextMessage(response)
        self.send(response, response.is_binary)