Fix pickle.load() EOFError: Ran out of input – Python Tutorial

By | February 3, 2023

When we are using python pickle to load an object, we may get this error: EOFError: Ran out of input. In this tutorial, we will introduce you how to fix it.

fix pickle.load() EOFError Ran out of input

Why does this error occur?

We can load an object from a file as follows:

with open("binary_list.bin","rb") as f:
    car_obj_2 = pickle.load(f)
print(car_obj_2)

However, if the file binary_list.bin is damaged or empty. We will get this error.

How to fix this error?

You have to remove binary_list.bin and save python object using python pickle again.

Best Practice to Save and Load Python Object From a File with Pickle – Python Tutorial