ValueError: binary mode doesn't take an encoding argument | error in pickle

697 Views Asked by At

Am using this code to read a file with pickle but inside an async function

    async with aiofiles.open("owners.pkl", mode="rb") as file:
    owner_dict = pickle.loads(await file.read())

But I get this error

    owner_dict = pickle.loads(await file.read())
    _pickle.UnpicklingError: invalid load key, '\xef'.

I just want a valid way to open files and read or write in them using pickle inside async-await functions

0

There are 0 best solutions below