# Buggy code
def reverse_readlines(
    filename,
    skip_empty=True,
    append_newline=False,
    block_size=512 * 1024,
    reset_offset=True,
    encoding="utf-8",
):
    """
    Flexible function for reversing read lines incrementally.

    This code is part of the flyingcircus package: https://pypi.org/project/flyingcircus/
    The code was adapted for our use case.
    All credits go to the original author.

    Args:
        filename (str): The input file name.
        skip_empty (bool): Skip empty lines.
        append_newline (bool):
        block_size (int|None): The block size.
            If int, the file is processed in blocks of the specified size.
            If None, the file is processed at once.
        reset_offset (bool): Reset the file offset.
            If True, starts reading from the end of the file.
            Otherwise, starts reading from where the file current position is.
        encoding (str|None): The encoding for correct block size computation.
            If `str`, must be a valid string encoding.
            If None, the default encoding is used.

    Yields:
        line (str): The next line.

    """
    newline = "\n"
    empty = ""
    remainder = empty
    block_generator_kws = dict(
        size=block_size, reset_offset=reset_offset, encoding=encoding
    )
    block_generator = blocks_r
    for block in block_generator(filename, **block_generator_kws):
        lines = block.split(newline)
        if remainder:
            lines[-1] = lines[-1] + remainder
        remainder = lines[0]
        mask = slice(-1, 0, -1)
        for line in lines[mask]:
            if line or not skip_empty:
                yield line + (newline if append_newline else empty)
    if remainder or not skip_empty:
        yield remainder + (newline if append_newline else empty)


# Traceback (UnicodeDecodeError)
2019-07-09 08:24:58 ERROR	TORNADO :: 74c3f12] Uncaught exception in APIv2: UnicodeDecodeError('utf8', "\xb8./.Barry.[02x01-07.\xd0\xb8\xd0\xb7.08].(2019).WEBRip.720p.|.Gears.Media\n2019-07-09 08:13:14 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [Zooqle :: [74c3f12] 333072: Allowed, Preferred = [ 720p WEB-DL, 1080p WEB-DL, 720p BluRay, 1080p BluRay ] [ 1080p BluRay ] Found = [ 720p WEB-DL ]\n2019-07-09 08:13:14 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [Zooqle] :: [74c3f12] 333072: 'Barry' S02E01 status is: 'Downloaded'. Ignoring result with quality '720p WEB-DL'. Reason: New quality is same/lower quality (and not preferred). Ignoring new quality\n2019-07-09 08:13:14 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [Zooqle] :: [74c3f12] Ignoring \xd0\x91\xd0\xb0\xd1\x80\xd1\x80\xd0\xb8./.Barry.[02x01-07.\xd0\xb8\xd0\xb7.08].(2019).WEBRip.720p.|.Gears.Media because one or more episodes are unwanted\n2019-07-09 08:13:14 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [Zooqle] :: [74c3f12] Using cached parse result for \xd0\x91\xd0\xb0\xd1\x80\xd1\x80\xd0\xb8./.Barry.[02x01-07.\xd0\xb8\xd0\xb7.08].(2019).WEBRip.|.Gears.Media\n2019-07-09 08:13:14 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [Zooqle] :: [74c3f12] 333072: Allowed, Preferred = [ 720p WEB-DL, 1080p WEB-DL, 720p BluRay, 1080p BluRay ] [ 1080p BluRay ] Found = [ SDTV ]\n2019-07-09 08:13:14 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [Zooqle] :: [74c3f12] 333072: Ignoring found result for 'Barry' S02E01 with unwanted quality 'SDTV'\n2019-07-09 08:13:14 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [Zooqle] :: [74c3f12] Ignoring \xd0\x91\xd0\xb0\xd1\x80\xd1\x80\xd0\xb8./.Barry.[02x01-07.\xd0\xb8\xd0\xb7.08].(2019).WEBRip.|.Gears.Media because one or more episodes are unwanted\n2019-07-09 08:13:14 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [Zooqle] :: [74c3f12] Using cached parse result for \xd0\x91\xd0\xb0\xd1\x80\xd1\x80\xd0\xb8./.Barry.[02x01-07.\xd0\xb8\xd0\xb7.08].(2019).WEBRip.|.Gears.Media\n2019-07-09 08:13:14 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [Zooqle] :: [74c3f12] 333072: Allowed, Preferred = [ 720p WEB-DL, 1080p WEB-DL, 720p BluRay, 1080p BluRay ] [ 1080p BluRay ] Found = [ SDTV ]\n2019-07-09 08:13:14 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [Zooqle] :: [74c3f12] 333072: Ignoring found result for 'Barry' S02E01 with unwanted quality 'SDTV'\n2019-07-09 08:13:14 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [Zooqle] :: [74c3f12] Ignoring \xd0\x91\xd0\xb0\xd1\x80\xd1\x80\xd0\xb8./.Barry.[02x01-07.\xd0\xb8\xd0\xb7.08].(2019).WEBRip.|.Gears.Media because one or more episodes are unwanted\n2019-07-09 08:13:14 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [Zooqle] :: [74c3f12] Using cached parse result for \xd0\x91\xd0\xb0\xd1\x80\xd1\x80\xd0\xb8./.Barry.[02x01-07.\xd0\xb8\xd0\xb7.08].(2019).WEBRip.1080p.|.IdeaFilm\n2019-07-09 08:13:14 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [Zooqle] :: [74c3f12] 333072: Allowed, Preferred = [ 720p WEB-DL, 1080p WEB-DL, 720p BluRay, 1080p BluRay ] [ 1080p BluRay ] Found = [ 1080p WEB-DL ]\n2019-07-09 08:13:14 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [Zooqle] :: [74c3f12] 333072: 'Barry' S02E01 status is: 'Downloaded'. Ignoring result with quality '1080p WEB-DL'. Reason: New quality is same/lower quality (and not preferred). Ignoring new quality\n2019-07-09 08:13:14 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [Zooqle] :: [74c3f12] Ignoring \xd0\x91\xd0\xb0\xd1\x80\xd1\x80\xd0\xb8./.Barry.[02x01-07.\xd0\xb8\xd0\xb7.08].(2019).WEBRip.1080p.|.IdeaFilm because one or more episodes are unwanted\n2019-07-09 08:13:14 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [Zooqle] :: [74c3f12] Using cached parse result for \xd0\x91\xd0\xb0\xd1\x80\xd1\x80\xd0\xb8./.Barry.[02x01-07.\xd0\xb8\xd0\xb7.08].(2019).WEBRip.720p.|.IdeaFilm\n2019-07-09 08:13:14 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [Zooqle] :: [74c3f12] 333072: Allowed, Preferred = [ 720p WEB-DL, 1080p WEB-DL, 720p BluRay, 1080p BluRay ] [ 1080p BluRay ] Found = [ 720p WEB-DL ]\n2019-07-09 08:13:14 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [Zooqle] :: [74c3f12] 333072: 'Barry' S02E01 status is: 'Downloaded'. Ignoring result with quality '720p WEB-DL'. Reason: New quality is same/lower quality (and not preferred). Ignoring new quality\n2019-07-09 08:13:14 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [Zooqle] :: [74c3f12] Ignoring \xd0\x91\xd0\xb0\xd1\x80\xd1\x80\xd0\xb8./.Barry.[02x01-07.\xd0\xb8\xd0\xb7.08].(2019).WEBRip.720p.|.IdeaFilm because one or more episodes are unwanted\n2019-07-09 08:13:14 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [Zooqle] :: [74c3f12] Using cached parse result for \xd0\x91\xd0\xb0\xd1\x80\xd1\x80\xd0\xb8./.Barry.[02x01-07.\xd0\xb8\xd0\xb7.08].(2019).WEBRip.|.IdeaFilm\n2019-07-09 08:13:14 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [Zooqle] :: [", 0, 1, 'invalid start byte')
Request: GET /api/v2/log?level=DEBUG&amp;thread=TORNADO&amp;period=one_day&amp;query=&amp;limit=1000 (24.254.133.76)
Traceback (most recent call last):
File "/home6/**********/.apps/medusa/medusa/ext/tornado/web.py", line 1592, in _execute
result = yield result
File "/home6/**********/.apps/medusa/medusa/ext/tornado/gen.py", line 1133, in run
value = future.result()
File "/home6/**********/.apps/medusa/medusa/ext/tornado/concurrent.py", line 261, in result
raise_exc_info(self._exc_info)
File "/home6/**********/.apps/medusa/medusa/ext/tornado/gen.py", line 1141, in run
yielded = self.gen.throw(*exc_info)
File "/home6/**********/.apps/medusa/medusa/medusa/server/api/v2/base.py", line 64, in async_call
content = yield IOLoop.current().run_in_executor(executor, prepared)
File "/home6/**********/.apps/medusa/medusa/ext/tornado/gen.py", line 1133, in run
value = future.result()
File "/home6/**********/.apps/medusa/medusa/ext/tornado/concurrent.py", line 261, in result
raise_exc_info(self._exc_info)
File "<string>", line 3, in raise_exc_info
UnicodeDecodeError: 'utf8' codec can't decode byte 0xb8 in position 0: invalid start byte
2019-07-09 08:22:53 ERROR	TORNADO :: 74c3f12] Uncaught exception in APIv2: UnicodeDecodeError('utf8', "\xb8\xd0\xb7.08].(2019).WEBRip.|.Gears.Media because one or more episodes are unwanted\n2019-07-09 08:13:14 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [Zooqle :: [74c3f12] Using cached parse result for \xd0\x91\xd0\xb0\xd1\x80\xd1\x80\xd0\xb8./.Barry.[02x01-07.\xd0\xb8\xd0\xb7.08].(2019).WEBRip.720p.|.Gears.Media\n2019-07-09 08:13:14 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [Zooqle] :: [74c3f12] 333072: Allowed, Preferred = [ 720p WEB-DL, 1080p WEB-DL, 720p BluRay, 1080p BluRay ] [ 1080p BluRay ] Found = [ 720p WEB-DL ]\n2019-07-09 08:13:14 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [Zooqle] :: [74c3f12] 333072: 'Barry' S02E01 status is: 'Downloaded'. Ignoring result with quality '720p WEB-DL'. Reason: New quality is same/lower quality (and not preferred). Ignoring new quality\n2019-07-09 08:13:14 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [Zooqle] :: [74c3f12] Ignoring \xd0\x91\xd0\xb0\xd1\x80\xd1\x80\xd0\xb8./.Barry.[02x01-07.\xd0\xb8\xd0\xb7.08].(2019).WEBRip.720p.|.Gears.Media because one or more episodes are unwanted\n2019-07-09 08:13:14 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [Zooqle] :: [74c3f12] Using cached parse result for \xd0\x91\xd0\xb0\xd1\x80\xd1\x80\xd0\xb8./.Barry.[02x01-07.\xd0\xb8\xd0\xb7.08].(2019).WEBRip.|.Gears.Media\n2019-07-09 08:13:14 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [Zooqle] :: [74c3f12] 333072: Allowed, Preferred = [ 720p WEB-DL, 1080p WEB-DL, 720p BluRay, 1080p BluRay ] [ 1080p BluRay ] Found = [ SDTV ]\n2019-07-09 08:13:14 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [Zooqle] :: [74c3f12] 333072: Ignoring found result for 'Barry' S02E01 with unwanted quality 'SDTV'\n2019-07-09 08:13:14 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [Zooqle] :: [74c3f12] Ignoring \xd0\x91\xd0\xb0\xd1\x80\xd1\x80\xd0\xb8./.Barry.[02x01-07.\xd0\xb8\xd0\xb7.08].(2019).WEBRip.|.Gears.Media because one or more episodes are unwanted\n2019-07-09 08:13:14 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [Zooqle] :: [74c3f12] Using cached parse result for \xd0\x91\xd0\xb0\xd1\x80\xd1\x80\xd0\xb8./.Barry.[02x01-07.\xd0\xb8\xd0\xb7.08].(2019).WEBRip.|.Gears.Media\n2019-07-09 08:13:14 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [Zooqle] :: [74c3f12] 333072: Allowed, Preferred = [ 720p WEB-DL, 1080p WEB-DL, 720p BluRay, 1080p BluRay ] [ 1080p BluRay ] Found = [ SDTV ]\n2019-07-09 08:13:14 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [Zooqle] :: [74c3f12] 333072: Ignoring found result for 'Barry' S02E01 with unwanted quality 'SDTV'\n2019-07-09 08:13:14 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [Zooqle] :: [74c3f12] Ignoring \xd0\x91\xd0\xb0\xd1\x80\xd1\x80\xd0\xb8./.Barry.[02x01-07.\xd0\xb8\xd0\xb7.08].(2019).WEBRip.|.Gears.Media because one or more episodes are unwanted\n2019-07-09 08:13:14 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [Zooqle] :: [74c3f12] Using cached parse result for \xd0\x91\xd0\xb0\xd1\x80\xd1\x80\xd0\xb8./.Barry.[02x01-07.\xd0\xb8\xd0\xb7.08].(2019).WEBRip.1080p.|.IdeaFilm\n2019-07-09 08:13:14 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [Zooqle] :: [74c3f12] 333072: Allowed, Preferred = [ 720p WEB-DL, 1080p WEB-DL, 720p BluRay, 1080p BluRay ] [ 1080p BluRay ] Found = [ 1080p WEB-DL ]\n2019-07-09 08:13:14 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [Zooqle] :: [74c3f12] 333072: 'Barry' S02E01 status is: 'Downloaded'. Ignoring result with quality '1080p WEB-DL'. Reason: New quality is same/lower quality (and not preferred). Ignoring new quality\n2019-07-09 08:13:14 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [Zooqle] :: [74c3f12] Ignoring \xd0\x91\xd0\xb0\xd1\x80\xd1\x80\xd0\xb8./.Barry.[02x01-07.\xd0\xb8\xd0\xb7.08].(2019).WEBRip.1080p.|.IdeaFilm because one or more episodes are unwanted\n2019-07-09 08:13:14 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [Zooqle] :: [74c3f12] Using cached parse result for \xd0\x91\xd0\xb0\xd1\x80\xd1\x80\xd0\xb8./.Barry.[02x01-07.\xd0\xb8\xd0\xb7.08].(2019).WEBRip.720p.|.IdeaFilm\n2019-07-09 08:13:14 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [Zooqle] :: [74c3f12] 333072: Allowed, Preferred = [ 720p WEB-DL, 1080p WEB-DL, 720p BluRay, 1080p BluRay ] [ 1080p BluRay ] Found = [ 720p WEB-DL ]\n2019-07-09 08:13:14 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [Zooqle] :: [74c3f12] 333072: 'Barry' S02E01 status is: 'Downloaded'. Ignoring result with quality '720p WEB-DL'. Reason: New quality is same/lower quality (and not preferred). Ignoring new quality\n2019-07-09 08:13:14 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [Zooqle] :: [74c3f12] Ignoring \xd0\x91\xd0\xb0\xd1\x80\xd1\x80\xd0\xb8./.Barry.[02x01-07.\xd0\xb8\xd0\xb7.08].(2019).WEBRip.720p.|.IdeaFilm because one or more episodes are unwanted\n2019-07-09 08:13:14 DEBUG    SEARCHQUEUE-DAILY", 0, 1, 'invalid start byte')
Request: GET /api/v2/log?level=WARNING&amp;thread=&amp;period=one_day&amp;query=&amp;limit=1000 (24.254.133.76)
Traceback (most recent call last):
File "/home6/**********/.apps/medusa/medusa/ext/tornado/web.py", line 1592, in _execute
result = yield result
File "/home6/**********/.apps/medusa/medusa/ext/tornado/gen.py", line 1133, in run
value = future.result()
File "/home6/**********/.apps/medusa/medusa/ext/tornado/concurrent.py", line 261, in result
raise_exc_info(self._exc_info)
File "/home6/**********/.apps/medusa/medusa/ext/tornado/gen.py", line 1141, in run
yielded = self.gen.throw(*exc_info)
File "/home6/**********/.apps/medusa/medusa/medusa/server/api/v2/base.py", line 64, in async_call
content = yield IOLoop.current().run_in_executor(executor, prepared)
File "/home6/**********/.apps/medusa/medusa/ext/tornado/gen.py", line 1133, in run
value = future.result()
File "/home6/**********/.apps/medusa/medusa/ext/tornado/concurrent.py", line 261, in result
raise_exc_info(self._exc_info)
File "<string>", line 3, in raise_exc_info
UnicodeDecodeError: 'utf8' codec can't decode byte 0xb8 in position 0: invalid start byte
2019-07-09 07:55:01 ERROR	TORNADO :: 74c3f12] Uncaught exception in APIv2: UnicodeDecodeError('utf8', '\xb7.13].(2019).WEBRip.720p.|.Kerob is 720p WEB-DL\n2019-07-08 19:49:43 INFO     SEARCHQUEUE-BACKLOG-268592 :: [Zooqle :: [74c3f12] Quality of \xd0\xa1\xd0\xbe\xd1\x82\xd0\xbd\xd1\x8f./.The.100.[06x01-04.\xd0\xb8\xd0\xb7.13].(2019).WEBRip.720p.|.LakeFilms is 720p WEB-DL\n2019-07-08 19:49:43 INFO     SEARCHQUEUE-BACKLOG-268592 :: [Zooqle] :: [74c3f12] Quality of \xd0\xa1\xd0\xbe\xd1\x82\xd0\xbd\xd1\x8f./.The.100.[06x01-04.\xd0\xb8\xd0\xb7.13].(2019).WEBRip.1080p.|.LakeFilms is 1080p WEB-DL\n2019-07-08 19:49:43 INFO     SEARCHQUEUE-BACKLOG-268592 :: [Zooqle] :: [74c3f12] Quality of \xd0\xa1\xd0\xbe\xd1\x82\xd0\xbd\xd1\x8f./.The.100.[06x01-04.\xd0\xb8\xd0\xb7.13].(2019).WEBRip.|.LakeFilms is SDTV\n2019-07-08 19:49:43 INFO     SEARCHQUEUE-BACKLOG-268592 :: [Zooqle] :: [74c3f12] Quality of \xd0\xa1\xd0\xbe\xd1\x82\xd0\xbd\xd1\x8f./.The.100.[06x01-04.\xd0\xb8\xd0\xb7.13].(2019).WEBRip.720p.|.Gears.Media is 720p WEB-DL\n2019-07-08 19:49:43 INFO     SEARCHQUEUE-BACKLOG-268592 :: [Zooqle] :: [74c3f12] Quality of \xd0\xa1\xd0\xbe\xd1\x82\xd0\xbd\xd1\x8f./.The.100.[06x01-04.\xd0\xb8\xd0\xb7.13].(2019).WEBRip.720p.|.Gears.Media is 720p WEB-DL\n2019-07-08 19:49:43 INFO     SEARCHQUEUE-BACKLOG-268592 :: [Zooqle] :: [74c3f12] Quality of \xd0\xa1\xd0\xbe\xd1\x82\xd0\xbd\xd1\x8f./.The.100.[06x01-04.\xd0\xb8\xd0\xb7.13].(2019).WEBRip.720p.|.Gears.Media is 720p WEB-DL\n2019-07-08 19:49:43 INFO     SEARCHQUEUE-BACKLOG-268592 :: [Zooqle] :: [74c3f12] Quality of \xd0\xa1\xd0\xbe\xd1\x82\xd0\xbd\xd1\x8f./.The.100.[06x01-04.\xd0\xb8\xd0\xb7.13].(2019).WEBRip.|.Gears.Media is SDTV\n2019-07-08 19:49:43 INFO     SEARCHQUEUE-BACKLOG-268592 :: [Zooqle] :: [74c3f12] Quality of \xd0\xa1\xd0\xbe\xd1\x82\xd0\xbd\xd1\x8f./.The.100.[06x01-05.\xd0\xb8\xd0\xb7.13].(2019).WEBRip.720p.|.Kerob is 720p WEB-DL\n2019-07-08 19:49:43 INFO     SEARCHQUEUE-BACKLOG-268592 :: [Zooqle] :: [74c3f12] Quality of \xd0\xa1\xd0\xbe\xd1\x82\xd0\xbd\xd1\x8f./.The.100.[06x01-05.\xd0\xb8\xd0\xb7.13].(2019).WEBRip.|.LakeFilms is SDTV\n2019-07-08 19:49:43 INFO     SEARCHQUEUE-BACKLOG-268592 :: [Zooqle] :: [74c3f12] Quality of \xd0\xa1\xd0\xbe\xd1\x82\xd0\xbd\xd1\x8f./.The.100.[06x01-05.\xd0\xb8\xd0\xb7.13].(2019).WEBRip.720p.|.LakeFilms is 720p WEB-DL\n2019-07-08 19:49:43 INFO     SEARCHQUEUE-BACKLOG-268592 :: [Zooqle] :: [74c3f12] Quality of \xd0\xa1\xd0\xbe\xd1\x82\xd0\xbd\xd1\x8f./.The.100.[06x01-05.\xd0\xb8\xd0\xb7.13].(2019).WEBRip.1080p.|.LakeFilms is 1080p WEB-DL\n2019-07-08 19:49:43 INFO     SEARCHQUEUE-BACKLOG-268592 :: [Zooqle] :: [74c3f12] Quality of \xd0\xa1\xd0\xbe\xd1\x82\xd0\xbd\xd1\x8f./.The.100.[06x01-05.\xd0\xb8\xd0\xb7.13].(2019).WEBRip.|.LakeFilms is SDTV\n2019-07-08 19:49:43 INFO     SEARCHQUEUE-BACKLOG-268592 :: [Zooqle] :: [74c3f12] Quality of \xd0\xa1\xd0\xbe\xd1\x82\xd0\xbd\xd1\x8f./.The.100.[06x01-05.\xd0\xb8\xd0\xb7.13].(2019).WEBRip.720p.|.LakeFilms is 720p WEB-DL\n2019-07-08 19:49:43 INFO     SEARCHQUEUE-BACKLOG-268592 :: [Zooqle] :: [74c3f12] Quality of \xd0\xa1\xd0\xbe\xd1\x82\xd0\xbd\xd1\x8f./.The.100.[06x01-05.\xd0\xb8\xd0\xb7.13].(2019).WEBRip.1080p.|.LakeFilms is 1080p WEB-DL\n2019-07-08 19:49:43 INFO     SEARCHQUEUE-BACKLOG-268592 :: [Zooqle] :: [74c3f12] Quality of \xd0\xa1\xd0\xbe\xd1\x82\xd0\xbd\xd1\x8f./.The.100.[06x01-05.\xd0\xb8\xd0\xb7.13].(2019).WEBRip.720p.|.Gears.Media is 720p WEB-DL\n2019-07-08 19:49:43 INFO     SEARCHQUEUE-BACKLOG-268592 :: [Zooqle] :: [74c3f12] Quality of \xd0\xa1\xd0\xbe\xd1\x82\xd0\xbd\xd1\x8f./.The.100.[06x01-05.\xd0\xb8\xd0\xb7.13].(2019).WEBRip.|.Gears.Media is SDTV\n2019-07-08 19:49:43 INFO     SEARCHQUEUE-BACKLOG-268592 :: [Zooqle] :: [74c3f12] Quality of \xd0\xa1\xd0\xbe\xd1\x82\xd0\xbd\xd1\x8f./.The.100.[06x01-05.\xd0\xb8\xd0\xb7.13].(2019).WEBRip.|.Gears.Media is SDTV\n2019-07-08 19:49:43 INFO     SEARCHQUEUE-BACKLOG-268592 :: [Zooqle] :: [74c3f12] Quality of \xd0\xa1\xd0\xbe\xd1\x82\xd0\xbd\xd1\x8f./.The.100.[06x01-05.\xd0\xb8\xd0\xb7.13].(2019).WEBRip.|.Gears.Media is SDTV\n2019-07-08 19:49:43 INFO     SEARCHQUEUE-BACKLOG-268592 :: [Zooqle] :: [74c3f12] Quality of \xd0\xa1\xd0\xbe\xd1\x82\xd0\xbd\xd1\x8f./.The.100.[06x01-05.\xd0\xb8\xd0\xb7.13].(2019).WEBRip.720p.|.BigSinema is 720p WEB-DL\n2019-07-08 19:49:43 INFO     SEARCHQUEUE-BACKLOG-268592 :: [Zooqle] :: [74c3f12] Quality of \xd0\xa1\xd0\xbe\xd1\x82\xd0\xbd\xd1\x8f./.The.100.[06x01-06.\xd0\xb8\xd0\xb7.13].(2019).WEBRip.1080p.|.LakeFilms is 1080p WEB-DL\n2019-07-08 19:49:43 INFO     SEARCHQUEUE-BACKLOG-268592 :: [Zooqle] :: [74c3f12] Quality of \xd0\xa1\xd0\xbe\xd1\x82\xd0\xbd\xd1\x8f./.The.100.[06x01-06.\xd0\xb8\xd0\xb7.13].(2019).WEBRip.|.LakeFilms is SDTV\n2019-07-08 19:49:43 INFO     SEARCHQUEUE-BACKLOG-268592 :: [Zooqle] :: [74c3f12] Quality of \xd0\xa1\xd0\xbe\xd1\x82\xd0\xbd\xd1\x8f./.The.100.[06x01-06.\xd0\xb8\xd0\xb7.13].(2019).WEBRip.720p.|.LakeFilms is 720p WEB-DL\n2019-07-08 19:49:43 INFO     SEARCHQUEUE-BACKLOG-268592 :: [Zooqle] :: [74c3f12] Quality of \xd0\xa1\xd0\xbe\xd1\x82\xd0\xbd\xd1\x8f./.The.100.[06x01-06.\xd0\xb8\xd0\xb7.13].(2019).WEBRip.720p.|.Gears.Media is 720p WEB-DL\n2019-07-08 19:49:43 INFO    ', 0, 1, 'invalid start byte')
Request: GET /api/v2/log?level=ERROR&amp;thread=&amp;period=one_day&amp;query=&amp;limit=1000 (24.254.133.76)
Traceback (most recent call last):
File "/home6/**********/.apps/medusa/medusa/ext/tornado/web.py", line 1592, in _execute
result = yield result
File "/home6/**********/.apps/medusa/medusa/ext/tornado/gen.py", line 1133, in run
value = future.result()
File "/home6/**********/.apps/medusa/medusa/ext/tornado/concurrent.py", line 261, in result
raise_exc_info(self._exc_info)
File "/home6/**********/.apps/medusa/medusa/ext/tornado/gen.py", line 1141, in run
yielded = self.gen.throw(*exc_info)
File "/home6/**********/.apps/medusa/medusa/medusa/server/api/v2/base.py", line 64, in async_call
content = yield IOLoop.current().run_in_executor(executor, prepared)
File "/home6/**********/.apps/medusa/medusa/ext/tornado/gen.py", line 1133, in run
value = future.result()
File "/home6/**********/.apps/medusa/medusa/ext/tornado/concurrent.py", line 261, in result
raise_exc_info(self._exc_info)
File "<string>", line 3, in raise_exc_info
UnicodeDecodeError: 'utf8' codec can't decode byte 0xb7 in position 0: invalid start byte
2019-07-09 07:54:26 ERROR	TORNADO :: 74c3f12] Uncaught exception in APIv2: UnicodeDecodeError('utf8', '\xbe\xd1\x87\xd0\xbd\xd1\x8b\xd0\xb5.\xd1\x81\xd0\xbe\xd0\xb1\xd1\x8b\xd1\x82\xd0\xb8\xd1\x8f./.Stranger.Things.[03x01-03.\xd0\xb8\xd0\xb7.8].(2019).WEBRip.1080p.|.Profix.Media is 1080p WEB-DL\n2019-07-08 20:27:27 INFO     SEARCHQUEUE-BACKLOG-305288 :: [Zooqle :: [74c3f12] Quality of \xd0\x9e\xd1\x87\xd0\xb5\xd0\xbd\xd1\x8c.\xd1\x81\xd1\x82\xd1\x80\xd0\xb0\xd0\xbd\xd0\xbd\xd1\x8b\xd0\xb5.\xd0\xb4\xd0\xb5\xd0\xbb\xd0\xb0./.Stranger.Things.[03x01-05.\xd0\xb8\xd0\xb7.08].(2019).WEBRip.|.OmskBird is SDTV\n2019-07-08 20:27:27 INFO     SEARCHQUEUE-BACKLOG-305288 :: [Zooqle] :: [74c3f12] Quality of \xd0\x9e\xd1\x87\xd0\xb5\xd0\xbd\xd1\x8c.\xd1\x81\xd1\x82\xd1\x80\xd0\xb0\xd0\xbd\xd0\xbd\xd1\x8b\xd0\xb5.\xd0\xb4\xd0\xb5\xd0\xbb\xd0\xb0./.Stranger.Things.[03x01-05.\xd0\xb8\xd0\xb7.08].(2019).WEBRip.720p.|.OmskBird is 720p WEB-DL\n2019-07-08 20:27:27 INFO     SEARCHQUEUE-BACKLOG-305288 :: [Zooqle] :: [74c3f12] Quality of \xd0\x9e\xd1\x87\xd0\xb5\xd0\xbd\xd1\x8c.\xd1\x81\xd1\x82\xd1\x80\xd0\xb0\xd0\xbd\xd0\xbd\xd1\x8b\xd0\xb5.\xd0\xb4\xd0\xb5\xd0\xbb\xd0\xb0./.Stranger.Things.[03x01-04.\xd0\xb8\xd0\xb7.08].(2019).WEB-DLRip-AVC.|.\xd0\x9f\xd0\xb8\xd1\x84\xd0\xb0\xd0\xb3\xd0\xbe\xd1\x80 is SDTV\n2019-07-08 20:27:27 INFO     SEARCHQUEUE-BACKLOG-305288 :: [Zooqle] :: [74c3f12] Quality of \xd0\x9e\xd1\x87\xd0\xb5\xd0\xbd\xd1\x8c.\xd1\x81\xd1\x82\xd1\x80\xd0\xb0\xd0\xbd\xd0\xbd\xd1\x8b\xd0\xb5.\xd0\xb4\xd0\xb5\xd0\xbb\xd0\xb0./.Stranger.Things.[03x01-04.\xd0\xb8\xd0\xb7.08].(2019).WEB-DLRip.|.\xd0\x9f\xd0\xb8\xd1\x84\xd0\xb0\xd0\xb3\xd0\xbe\xd1\x80 is SDTV\n2019-07-08 20:27:27 INFO     SEARCHQUEUE-BACKLOG-305288 :: [Zooqle] :: [74c3f12] Quality of \xd0\x9e\xd1\x87\xd0\xb5\xd0\xbd\xd1\x8c.\xd1\x81\xd1\x82\xd1\x80\xd0\xb0\xd0\xbd\xd0\xbd\xd1\x8b\xd0\xb5.\xd0\xb4\xd0\xb5\xd0\xbb\xd0\xb0./.Stranger.Things.[03x01-03.\xd0\xb8\xd0\xb7.08].(2019).WEBRip.|.OmskBird is SDTV\n2019-07-08 20:27:27 INFO     SEARCHQUEUE-BACKLOG-305288 :: [Zooqle] :: [74c3f12] Quality of \xd0\x9e\xd1\x87\xd0\xb5\xd0\xbd\xd1\x8c.\xd1\x81\xd1\x82\xd1\x80\xd0\xb0\xd0\xbd\xd0\xbd\xd1\x8b\xd0\xb5.\xd0\xb4\xd0\xb5\xd0\xbb\xd0\xb0./.Stranger.Things.[03x01-03.\xd0\xb8\xd0\xb7.08].(2019).WEBRip.720p.|.OmskBird is 720p WEB-DL\n2019-07-08 20:27:27 INFO     SEARCHQUEUE-BACKLOG-305288 :: [Zooqle] :: [74c3f12] Quality of \xd0\x9e\xd1\x87\xd0\xb5\xd0\xbd\xd1\x8c.\xd1\x81\xd1\x82\xd1\x80\xd0\xb0\xd0\xbd\xd0\xbd\xd1\x8b\xd0\xb5.\xd0\xb4\xd0\xb5\xd0\xbb\xd0\xb0./.Stranger.Things.[03x01-03.\xd0\xb8\xd0\xb7.08].(2019).WEBRip.|.OmskBird is SDTV\n2019-07-08 20:27:27 INFO     SEARCHQUEUE-BACKLOG-305288 :: [Zooqle] :: [74c3f12] Quality of \xd0\x9e\xd1\x87\xd0\xb5\xd0\xbd\xd1\x8c.\xd1\x81\xd1\x82\xd1\x80\xd0\xb0\xd0\xbd\xd0\xbd\xd1\x8b\xd0\xb5.\xd0\xb4\xd0\xb5\xd0\xbb\xd0\xb0./.\xd0\x97\xd0\xb0\xd0\xb3\xd0\xb0\xd0\xb4\xd0\xbe\xd1\x87\xd0\xbd\xd1\x8b\xd0\xb5.\xd1\x81\xd0\xbe\xd0\xb1\xd1\x8b\xd1\x82\xd0\xb8\xd1\x8f./.Stranger.Things.[03x01-03.\xd0\xb8\xd0\xb7.8].(2019).WEBRip.|.Profix.Media is SDTV\n2019-07-08 20:27:27 INFO     SEARCHQUEUE-BACKLOG-305288 :: [Zooqle] :: [74c3f12] Quality of \xd0\x9e\xd1\x87\xd0\xb5\xd0\xbd\xd1\x8c.\xd1\x81\xd1\x82\xd1\x80\xd0\xb0\xd0\xbd\xd0\xbd\xd1\x8b\xd0\xb5.\xd0\xb4\xd0\xb5\xd0\xbb\xd0\xb0./.\xd0\x97\xd0\xb0\xd0\xb3\xd0\xb0\xd0\xb4\xd0\xbe\xd1\x87\xd0\xbd\xd1\x8b\xd0\xb5.\xd1\x81\xd0\xbe\xd0\xb1\xd1\x8b\xd1\x82\xd0\xb8\xd1\x8f./.Stranger.Things.[03x01-03.\xd0\xb8\xd0\xb7.8].(2019).WEBRip.1080p.|.Profix.Media is 1080p WEB-DL\n2019-07-08 20:27:27 INFO     SEARCHQUEUE-BACKLOG-305288 :: [Zooqle] :: [74c3f12] Quality of \xd0\x9e\xd1\x87\xd0\xb5\xd0\xbd\xd1\x8c.\xd1\x81\xd1\x82\xd1\x80\xd0\xb0\xd0\xbd\xd0\xbd\xd1\x8b\xd0\xb5.\xd0\xb4\xd0\xb5\xd0\xbb\xd0\xb0./.Stranger.Things.[03x01-05.\xd0\xb8\xd0\xb7.08].(2019).WEBRip.|.OmskBird is SDTV\n2019-07-08 20:27:27 INFO     SEARCHQUEUE-BACKLOG-305288 :: [Zooqle] :: [74c3f12] Quality of \xd0\x9e\xd1\x87\xd0\xb5\xd0\xbd\xd1\x8c.\xd1\x81\xd1\x82\xd1\x80\xd0\xb0\xd0\xbd\xd0\xbd\xd1\x8b\xd0\xb5.\xd0\xb4\xd0\xb5\xd0\xbb\xd0\xb0./.Stranger.Things.[03x01-05.\xd0\xb8\xd0\xb7.08].(2019).WEBRip.720p.|.OmskBird is 720p WEB-DL\n2019-07-08 20:27:27 INFO     SEARCHQUEUE-BACKLOG-305288 :: [Zooqle] :: [74c3f12] Quality of \xd0\x9e\xd1\x87\xd0\xb5\xd0\xbd\xd1\x8c.\xd1\x81\xd1\x82\xd1\x80\xd0\xb0\xd0\xbd\xd0\xbd\xd1\x8b\xd0\xb5.\xd0\xb4\xd0\xb5\xd0\xbb\xd0\xb0./.Stranger.Things.[03x01-04.\xd0\xb8\xd0\xb7.08].(2019).WEB-DLRip-AVC.|.\xd0\x9f\xd0\xb8\xd1\x84\xd0\xb0\xd0\xb3\xd0\xbe\xd1\x80 is SDTV\n2019-07-08 20:27:27 INFO     SEARCHQUEUE-BACKLOG-305288 :: [Zooqle] :: [74c3f12] Quality of \xd0\x9e\xd1\x87\xd0\xb5\xd0\xbd\xd1\x8c.\xd1\x81\xd1\x82\xd1\x80\xd0\xb0\xd0\xbd\xd0\xbd\xd1\x8b\xd0\xb5.\xd0\xb4\xd0\xb5\xd0\xbb\xd0\xb0./.Stranger.Things.[03x01-04.\xd0\xb8\xd0\xb7.08].(2019).WEB-DLRip.|.\xd0\x9f\xd0\xb8\xd1\x84\xd0\xb0\xd0\xb3\xd0\xbe\xd1\x80 is SDTV\n2019-07-08 20:27:27 INFO     SEARCHQUEUE-BACKLOG-305288 :: [Zooqle] :: [74c3f12] Quality of \xd0\x9e\xd1\x87\xd0\xb5\xd0\xbd\xd1\x8c.\xd1\x81\xd1\x82\xd1\x80\xd0\xb0\xd0\xbd\xd0\xbd\xd1\x8b\xd0\xb5.\xd0\xb4\xd0\xb5\xd0\xbb\xd0\xb0./.Stranger.Things.[03x01-03.\xd0\xb8\xd0\xb7.08].(2019).WEBRip.|.OmskBird is SDTV\n2019-07-08 20:27:27 INFO     SEARCHQUEUE-BACKLOG-305288 :: [Zooqle] :: [74c3f12] Quality of \xd0\x9e\xd1\x87\xd0\xb5\xd0\xbd\xd1\x8c.\xd1\x81\xd1\x82\xd1\x80\xd0\xb0\xd0\xbd\xd0\xbd\xd1\x8b\xd0\xb5.\xd0\xb4\xd0\xb5\xd0\xbb\xd0\xb0./.Stranger.Things.[03x01-03.\xd0\xb8\xd0\xb7.08].(2019).WEBRip.720p.|.OmskBird is 720p WEB-DL\n2019-07-08 20:27:27 INFO     SEARCHQUEUE-BACKLOG-305288 :: [Zooqle] :: [74c3f12] Quality of \xd0\x9e\xd1\x87\xd0\xb5\xd0\xbd\xd1\x8c.\xd1\x81\xd1\x82\xd1\x80\xd0\xb0\xd0\xbd\xd0\xbd\xd1\x8b\xd0\xb5.\xd0\xb4\xd0\xb5\xd0\xbb\xd0\xb0./.Stranger.Things.[03x01-03.\xd0\xb8\xd0\xb7.08].(2019).WEBRip.|.OmskBird is SDTV\n2019-07-08 20:27:27 INFO     SEARCHQUEUE-BACKLOG-305288 :: [Zooqle] :: [74c3f12] Quality of \xd0\x9e\xd1\x87\xd0\xb5\xd0\xbd\xd1\x8c.\xd1\x81\xd1\x82\xd1\x80\xd0\xb0\xd0\xbd\xd0\xbd\xd1\x8b\xd0\xb5.\xd0\xb4\xd0\xb5\xd0\xbb\xd0\xb0./.\xd0\x97\xd0\xb0\xd0\xb3\xd0\xb0\xd0\xb4\xd0\xbe\xd1\x87\xd0\xbd\xd1\x8b\xd0\xb5.\xd1\x81\xd0\xbe\xd0\xb1\xd1\x8b\xd1\x82\xd0\xb8\xd1\x8f./.Stranger.Things.[03x01-03.\xd0\xb8\xd0\xb7.8].(2019).WEBRip.|.Profix.Media is SDTV\n2019-07-08 20:27:27 INFO     SEARCHQUEUE-BACKLOG-305288 :: [Zooqle] :: [74c3f12] Quality of \xd0\x9e\xd1\x87\xd0\xb5\xd0\xbd\xd1\x8c.\xd1\x81\xd1\x82\xd1\x80\xd0\xb0\xd0\xbd\xd0\xbd\xd1\x8b\xd0\xb5.\xd0\xb4\xd0\xb5\xd0\xbb\xd0\xb0./.\xd0\x97\xd0\xb0\xd0\xb3\xd0\xb0\xd0\xb4\xd0\xbe\xd1\x87\xd0\xbd\xd1\x8b\xd0\xb5.\xd1\x81\xd0\xbe\xd0\xb1\xd1\x8b\xd1\x82\xd0\xb8\xd1\x8f./.Stranger.Things.[03x01-03.\xd0\xb8\xd0\xb7.8].(2019).WEBRip.1080p.|.Profix.Media is 1080p WEB-DL\n2019-07-08 20:27:27 INFO     SEARCHQUEUE-BACKLOG-305288 :: [Zooqle] :: [74c3f12] Quality of \xd0\x9e\xd1\x87\xd0\xb5\xd0\xbd\xd1\x8c.\xd1\x81\xd1\x82\xd1\x80\xd0\xb0\xd0\xbd\xd0\xbd\xd1\x8b\xd0', 0, 1, 'invalid start byte')
Request: GET /api/v2/log?level=WARNING&amp;thread=&amp;period=one_day&amp;query=&amp;limit=1000 (24.254.133.76)
Traceback (most recent call last):
File "/home6/**********/.apps/medusa/medusa/ext/tornado/web.py", line 1592, in _execute
result = yield result
File "/home6/**********/.apps/medusa/medusa/ext/tornado/gen.py", line 1133, in run
value = future.result()
File "/home6/**********/.apps/medusa/medusa/ext/tornado/concurrent.py", line 261, in result
raise_exc_info(self._exc_info)
File "/home6/**********/.apps/medusa/medusa/ext/tornado/gen.py", line 1141, in run
yielded = self.gen.throw(*exc_info)
File "/home6/**********/.apps/medusa/medusa/medusa/server/api/v2/base.py", line 64, in async_call
content = yield IOLoop.current().run_in_executor(executor, prepared)
File "/home6/**********/.apps/medusa/medusa/ext/tornado/gen.py", line 1133, in run
value = future.result()
File "/home6/**********/.apps/medusa/medusa/ext/tornado/concurrent.py", line 261, in result
raise_exc_info(self._exc_info)
File "<string>", line 3, in raise_exc_info

# Fixed code
def reverse_readlines(
    file_path,
    skip_empty=True,
    append_newline=False,
    block_size=128 * 1024,
    encoding="utf-8",
):
    """
    Flexible function for reversing read lines incrementally.

    This code is part of the flyingcircus package: https://pypi.org/project/flyingcircus/
    The code was adapted for our use case.
    All credits go to the original author.

    Args:
        file_path (str): The input file path.
        skip_empty (bool): Skip empty lines.
        append_newline (bool): Append a new line character at the end of each yielded line.
        block_size (int): The block size.
        encoding (str): The encoding for correct block size computation.

    Yields:
        line (str): The next line.

    """
    newline = "\n"
    empty = ""
    remainder = empty
    block_generator = blocks_r
    for block in block_generator(file_path, size=block_size):
        lines = block.split(b"\n")
        if remainder:
            lines[-1] = lines[-1] + remainder
        remainder = lines[0]
        mask = slice(-1, 0, -1)
        for line in lines[mask]:
            if line or not skip_empty:
                yield line.decode(encoding) + (newline if append_newline else empty)
    if remainder or not skip_empty:
        yield remainder.decode(encoding) + (newline if append_newline else empty)