# Buggy code
def get_content(self, strict: bool = True) -> bytes:
    """
    The HTTP message body decoded with the content-encoding header (e.g. gzip)

    Raises:
        ValueError, when the content-encoding is invalid and strict is True.

    See also: :py:class:`raw_content`, :py:attr:`text`
    """
    if self.raw_content is None:
        return None
    ce = self.headers.get("content-encoding")
    if ce:
        try:
            return encoding.decode(self.raw_content, ce)
        except ValueError:
            if strict:
                raise
            return self.raw_content
    else:
        return self.raw_content


# Traceback (AttributeError)
Traceback (most recent call last):
File "/usr/lib/python3.5/site-packages/mitmproxy/contentviews.py", line 657, in get_content_view
ret = viewmode(data, **metadata)
File "/usr/lib/python3.5/site-packages/mitmproxy/contentviews.py", line 138, in __call__
return content_types_map[ct][0](data, **metadata)
File "/usr/lib/python3.5/site-packages/mitmproxy/contentviews.py", line 228, in __call__
pj = pretty_json(data)
File "/usr/lib/python3.5/site-packages/mitmproxy/contentviews.py", line 55, in pretty_json
p = json.loads(s.decode('utf-8'))
AttributeError: 'str' object has no attribute 'decode'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/usr/lib/python3.5/site-packages/mitmproxy/console/master.py", line 482, in run
self.loop.run()
File "/usr/lib/python3.5/site-packages/urwid/main_loop.py", line 278, in run
self._run()
File "/usr/lib/python3.5/site-packages/urwid/main_loop.py", line 376, in _run
self.event_loop.run()
File "/usr/lib/python3.5/site-packages/urwid/main_loop.py", line 682, in run
self._loop()
File "/usr/lib/python3.5/site-packages/urwid/main_loop.py", line 719, in _loop
self._watch_files[fd]()
File "/usr/lib/python3.5/site-packages/urwid/raw_display.py", line 393, in <lambda>
event_loop, callback, self.get_available_raw_input())
File "/usr/lib/python3.5/site-packages/urwid/raw_display.py", line 493, in parse_input
callback(processed, processed_codes)
File "/usr/lib/python3.5/site-packages/urwid/main_loop.py", line 403, in _update
self.process_input(keys)
File "/usr/lib/python3.5/site-packages/urwid/main_loop.py", line 503, in process_input
k = self._topmost_widget.keypress(self.screen_size, k)
File "/usr/lib/python3.5/site-packages/mitmproxy/console/window.py", line 86, in keypress
k = super(self.__class__, self).keypress(size, k)
File "/usr/lib/python3.5/site-packages/urwid/container.py", line 1128, in keypress
return self.body.keypress( (maxcol, remaining), key )
File "/usr/lib/python3.5/site-packages/mitmproxy/console/flowlist.py", line 385, in keypress
return urwid.ListBox.keypress(self, size, key)
File "/usr/lib/python3.5/site-packages/urwid/listbox.py", line 985, in keypress
key = focus_widget.keypress((maxcol,),key)
File "/usr/lib/python3.5/site-packages/mitmproxy/console/flowlist.py", line 238, in keypress
self.master.view_flow(self.flow)
File "/usr/lib/python3.5/site-packages/mitmproxy/console/master.py", line 576, in view_flow
flowview.FlowView(self, self.state, flow, tab_offset),
File "/usr/lib/python3.5/site-packages/mitmproxy/console/flowview.py", line 143, in __init__
tab_offset
File "/usr/lib/python3.5/site-packages/mitmproxy/console/tabs.py", line 31, in __init__
self.show()
File "/usr/lib/python3.5/site-packages/mitmproxy/console/tabs.py", line 69, in show
body = self.tabs[self.tab_offset][1](),
File "/usr/lib/python3.5/site-packages/mitmproxy/console/flowview.py", line 166, in view_request
return self.conn_text(self.flow.request)
File "/usr/lib/python3.5/site-packages/mitmproxy/console/flowview.py", line 260, in conn_text
msg, body = self.content_view(viewmode, conn)
File "/usr/lib/python3.5/site-packages/mitmproxy/console/flowview.py", line 203, in content_view
flow_modify_cache_invalidation
File "/usr/lib/python3.5/site-packages/mitmproxy/utils.py", line 32, in get
ret = gen(*args)
File "/usr/lib/python3.5/site-packages/mitmproxy/console/flowview.py", line 200, in <lambda>
lambda *args: self._get_content_view(message, *args),
File "/usr/lib/python3.5/site-packages/mitmproxy/console/flowview.py", line 208, in _get_content_view
viewmode, message
File "/usr/lib/python3.5/site-packages/mitmproxy/contentviews.py", line 635, in get_message_content_view
viewmode, content, headers=headers, query=query
File "/usr/lib/python3.5/site-packages/mitmproxy/contentviews.py", line 665, in get_content_view
_, content = get("Raw")(data, **metadata)
File "/usr/lib/python3.5/site-packages/mitmproxy/contentviews.py", line 156, in __call__
return "Raw", format_text(strutils.bytes_to_escaped_str(data, True))
File "/usr/lib/python3.5/site-packages/netlib/strutils.py", line 88, in bytes_to_escaped_str
raise ValueError("data must be bytes, but is {}".format(data.__class__.__name__))
ValueError: data must be bytes, but is str

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

# Fixed code
def get_content(self, strict: bool = True) -> bytes:
    """
    The HTTP message body decoded with the content-encoding header (e.g. gzip)

    Raises:
        ValueError, when the content-encoding is invalid and strict is True.

    See also: :py:class:`raw_content`, :py:attr:`text`
    """
    if self.raw_content is None:
        return None
    ce = self.headers.get("content-encoding")
    if ce:
        try:
            content = encoding.decode(self.raw_content, ce)
            # A client may illegally specify a byte -> str encoding here (e.g. utf8)
            if isinstance(content, str):
                raise ValueError("Invalid Content-Encoding: {}".format(ce))
            return content
        except ValueError:
            if strict:
                raise
            return self.raw_content
    else:
        return self.raw_content