jsonpython-3.xfirefoxunicodelz4

'utf-8' codec can't decode byte 0xf0 in position 12 on LZ4 and Python 3.x


I am using lz4 and JSON to decode the recovery.jsonlz4 file from firefox directory. But, I keep getting this error.

Firefox version: 69.0

 #!/usr/bin/python3

import os, json, lz4.block

f = open("/home/<userName>/.mozilla/firefox/or9wxah0.default/sessionstore-backups/recovery.jsonlz4", "r")
magic = f.read(8)
jdata = json.loads(lz4.block.decompress(f.read()).decode("utf-8"))
f.close()
for win in jdata.get("windows"):
    for tab in win.get("tabs"):
        i = int(tab.get("index")) - 1
        urls = tab.get("entries")[i].get("url")
        print(urls)

ERROR:

UnicodeDecodeError: 'utf-8' codec can't decode byte 0xf0 in position 12: invalid continuation byte

Solution

  • SOLVED:

    Forgot to add 'rb'

    f = open("/home/<userName>/.mozilla/firefox/or9wxah0.default/sessionstore-backups/recovery.jsonlz4", "rb")