# Buggy code
def event(method, data=None, sender=None, hexlify=False):
    """Data is a dictionary."""
    data = data or {}
    sender = sender or "plugin.video.jellyfin"

    if hexlify:
        data = '\\"[\\"{0}\\"]\\"'.format(binascii.hexlify(json.dumps(data)))
    else:
        data = '"[%s]"' % json.dumps(data).replace('"', '\\"')

    xbmc.executebuiltin("NotifyAll(%s, %s, %s)" % (sender, method, data))
    LOG.debug("---[ event: %s/%s ] %s", sender, method, data)


# Traceback (TypeError)
2020-12-09 21:34:39.454 T:3534  NOTICE: Creating InputStream
2020-12-09 21:34:47.723 T:3458  NOTICE: VideoInfoScanner: Starting scan ..
2020-12-09 21:34:47.728 T:3458  NOTICE: VideoInfoScanner: Finished scan. Scanning for video info took 00:00
2020-12-09 21:34:53.734 T:3534  NOTICE: Creating Demuxer
2020-12-09 21:34:54.188 T:3534  NOTICE: Opening stream: 1 source: 256
2020-12-09 21:34:54.188 T:3534  NOTICE: Creating video codec with codec id: 173
2020-12-09 21:34:54.188 T:3534  NOTICE: CDVDVideoCodecDRMPRIME::Open - using decoder HEVC (High Efficiency Video Coding)
2020-12-09 21:34:54.190 T:3534  NOTICE: Creating video thread
2020-12-09 21:34:54.191 T:3545  NOTICE: running thread: video_thread
2020-12-09 21:34:54.419 T:3534  NOTICE: Opening stream: 0 source: 256
2020-12-09 21:34:54.420 T:3534  NOTICE: Finding audio codec for: 86018
2020-12-09 21:34:54.422 T:3534  NOTICE: CDVDAudioCodecFFmpeg::Open() Successful opened audio decoder aac
2020-12-09 21:34:54.422 T:3534  NOTICE: Creating audio thread
2020-12-09 21:34:54.427 T:3547  NOTICE: running thread: CVideoPlayerAudio::Process()
2020-12-09 21:34:54.439 T:3547  NOTICE: Creating audio stream (codec id: 86018, channels: 2, sample rate: 48000, no pass-through)
2020-12-09 21:35:08.489 T:3545 WARNING: CRenderManager::WaitForBuffer - timeout waiting for buffer
2020-12-09 21:35:39.038 T:3501 WARNING: Previous line repeats 13 times.
2020-12-09 21:35:39.038 T:3501   ERROR: EXCEPTION Thrown (PythonToCppException) : -->Python callback/script returned the following error<--
- NOTE: IGNORING THIS CAN LEAD TO MEMORY LEAKS!
Error Type: <class 'TypeError'>
Error Contents: a bytes-like object is required, not 'str'
Traceback (most recent call last):
File "/storage/.kodi/addons/plugin.video.jellyfin/jellyfin_kodi/monitor.py", line 252, in onNotification
self.player.report_playback(data.get('Report', True))
File "/storage/.kodi/addons/plugin.video.jellyfin/jellyfin_kodi/player.py", line 341, in report_playback
self.next_up()
File "/storage/.kodi/addons/plugin.video.jellyfin/jellyfin_kodi/player.py", line 281, in next_up
event("upnext_data", next_info, hexlify=True)
File "/storage/.kodi/addons/plugin.video.jellyfin/jellyfin_kodi/helper/utils.py", line 140, in event
data = '\\"[\\"{0}\\"]\\"'.format(binascii.hexlify(json.dumps(data)))
TypeError: a bytes-like object is required, not 'str'
-->End of Python script error report<--
2020-12-09 21:35:39.989 T:3445  NOTICE: Samba is idle. Closing the remaining connections
2020-12-09 21:36:19.394 T:3545 WARNING: CRenderManager::WaitForBuffer - timeout waiting for buffer

# Fixed code
def event(method, data=None, sender=None, hexlify=False):
    """Data is a dictionary."""
    data = data or {}
    sender = sender or "plugin.video.jellyfin"

    if hexlify:
        data = ensure_text(binascii.hexlify(ensure_binary(json.dumps(data))))

    data = '"[%s]"' % json.dumps(data).replace('"', '\\"')

    LOG.debug("---[ event: %s/%s ] %s", sender, method, data)

    xbmc.executebuiltin("NotifyAll(%s, %s, %s)" % (sender, method, data))