# Buggy code
def __init__(self, client_conn, server_conn, handshake_flow, live=None):
    super().__init__("websocket", client_conn, server_conn, live)
    self.messages = []  # type: List[WebSocketMessage]
    self.close_sender = "client"
    self.close_code = "(status code missing)"
    self.close_message = "(message missing)"
    self.close_reason = "unknown status code"
    self.handshake_flow = handshake_flow


# Traceback (ValueError)
Traceback (most recent call last):
File "/usr/local/Cellar/mitmproxy/2.0.0/libexec/lib/python3.6/site-packages/mitmproxy/tools/console/master.py", line 281, in run
self.loop.run()
File "/usr/local/Cellar/mitmproxy/2.0.0/libexec/lib/python3.6/site-packages/urwid/main_loop.py", line 278, in run
self._run()
File "/usr/local/Cellar/mitmproxy/2.0.0/libexec/lib/python3.6/site-packages/urwid/main_loop.py", line 376, in _run
self.event_loop.run()
File "/usr/local/Cellar/mitmproxy/2.0.0/libexec/lib/python3.6/site-packages/urwid/main_loop.py", line 682, in run
self._loop()
File "/usr/local/Cellar/mitmproxy/2.0.0/libexec/lib/python3.6/site-packages/urwid/main_loop.py", line 719, in _loop
self._watch_files[fd]()
File "/usr/local/Cellar/mitmproxy/2.0.0/libexec/lib/python3.6/site-packages/urwid/raw_display.py", line 393, in <lambda>
event_loop, callback, self.get_available_raw_input())
File "/usr/local/Cellar/mitmproxy/2.0.0/libexec/lib/python3.6/site-packages/urwid/raw_display.py", line 493, in parse_input
callback(processed, processed_codes)
File "/usr/local/Cellar/mitmproxy/2.0.0/libexec/lib/python3.6/site-packages/urwid/main_loop.py", line 403, in _update
self.process_input(keys)
File "/usr/local/Cellar/mitmproxy/2.0.0/libexec/lib/python3.6/site-packages/urwid/main_loop.py", line 503, in process_input
k = self._topmost_widget.keypress(self.screen_size, k)
File "/usr/local/Cellar/mitmproxy/2.0.0/libexec/lib/python3.6/site-packages/mitmproxy/tools/console/window.py", line 84, in keypress
k = super().keypress(size, k)
File "/usr/local/Cellar/mitmproxy/2.0.0/libexec/lib/python3.6/site-packages/urwid/container.py", line 1116, in keypress
return self.footer.keypress((maxcol,),key)
File "/usr/local/Cellar/mitmproxy/2.0.0/libexec/lib/python3.6/site-packages/mitmproxy/tools/console/statusbar.py", line 155, in keypress
return self.master.ab.keypress(*args, **kwargs)
File "/usr/local/Cellar/mitmproxy/2.0.0/libexec/lib/python3.6/site-packages/mitmproxy/tools/console/statusbar.py", line 110, in keypress
self.prompt_execute(self._w.get_edit_text())
File "/usr/local/Cellar/mitmproxy/2.0.0/libexec/lib/python3.6/site-packages/mitmproxy/tools/console/statusbar.py", line 133, in prompt_execute
msg = p(txt)
File "/usr/local/Cellar/mitmproxy/2.0.0/libexec/lib/python3.6/site-packages/mitmproxy/tools/console/statusbar.py", line 21, in __call__
return self.callback(pth, *self.args)
File "/usr/local/Cellar/mitmproxy/2.0.0/libexec/lib/python3.6/site-packages/mitmproxy/tools/console/master.py", line 388, in save_flows
return self._write_flows(path, self.view)
File "/usr/local/Cellar/mitmproxy/2.0.0/libexec/lib/python3.6/site-packages/mitmproxy/tools/console/master.py", line 382, in _write_flows
fw.add(i)
File "/usr/local/Cellar/mitmproxy/2.0.0/libexec/lib/python3.6/site-packages/mitmproxy/io.py", line 27, in add
tnetstring.dump(d, self.fo)
File "/usr/local/Cellar/mitmproxy/2.0.0/libexec/lib/python3.6/site-packages/mitmproxy/contrib/tnetstring.py", line 66, in dump
file_handle.write(dumps(value))
File "/usr/local/Cellar/mitmproxy/2.0.0/libexec/lib/python3.6/site-packages/mitmproxy/contrib/tnetstring.py", line 57, in dumps
_rdumpq(q, 0, value)
File "/usr/local/Cellar/mitmproxy/2.0.0/libexec/lib/python3.6/site-packages/mitmproxy/contrib/tnetstring.py", line 142, in _rdumpq
size = _rdumpq(q, size, v)
File "/usr/local/Cellar/mitmproxy/2.0.0/libexec/lib/python3.6/site-packages/mitmproxy/contrib/tnetstring.py", line 142, in _rdumpq
size = _rdumpq(q, size, v)
File "/usr/local/Cellar/mitmproxy/2.0.0/libexec/lib/python3.6/site-packages/mitmproxy/contrib/tnetstring.py", line 149, in _rdumpq
raise ValueError("unserializable object: {} ({})".format(value, type(value)))
ValueError: unserializable object: <WebSocketFlow (69 messages)> (<class 'mitmproxy.websocket.WebSocketFlow'>)

mitmproxy has crashed!
Please lodge a bug report at:
https://github.com/mitmproxy/mitmproxy
Shutting down...

# Fixed code
def __init__(self, client_conn, server_conn, handshake_flow, live=None):
    super().__init__("websocket", client_conn, server_conn, live)
    self.messages = []  # type: List[WebSocketMessage]
    self.close_sender = "client"
    self.close_code = "(status code missing)"
    self.close_message = "(message missing)"
    self.close_reason = "unknown status code"

    if handshake_flow:
        self.client_key = websockets.get_client_key(handshake_flow.request.headers)
        self.client_protocol = websockets.get_protocol(handshake_flow.request.headers)
        self.client_extensions = websockets.get_extensions(
            handshake_flow.request.headers
        )
        self.server_accept = websockets.get_server_accept(
            handshake_flow.response.headers
        )
        self.server_protocol = websockets.get_protocol(handshake_flow.response.headers)
        self.server_extensions = websockets.get_extensions(
            handshake_flow.response.headers
        )
    else:
        self.client_key = ""
        self.client_protocol = ""
        self.client_extensions = ""
        self.server_accept = ""
        self.server_protocol = ""
        self.server_extensions = ""

    self.handshake_flow = handshake_flow