How to solve "EOFError: Ran out of input" if the pickle file isn't empty?

2.5k Views Asked by At

I'm trying to unpickle serial data from Drive using GoogleColab, but it appears the error "EOFError: Ran out of input". I checked out to see if the file was empty, but it isn't. It returns 81440157 bytes.

A = '/content/drive/MyDrive/Colab Notebooks/DataSet/Cars/SerialData/X_training'
print(os.path.getsize(A))


81440157 

So, at the moment to unpickle the data, the mentioned error appears in spite of an "if" condition is true about the size data.

with open(A, 'rb') as M:
 Unpicker = pickle.load(M)

---------------------------------------------------------------------------
EOFError                                  Traceback (most recent call last)
<ipython-input-28-3ef5056b9f71> in <module>
      2 print(os.path.getsize(A))
      3 with open(A, 'rb') as M:
----> 4  Unpicker = pickle.load(M)

EOFError: Ran out of input

I tried to use an "if" to avoid the error according with the size data; "if the data size is bigger than 0, execute the unpicker process". Therefore, the error still in spait of the "if" condition mentioned.

A = '/content/drive/MyDrive/Colab Notebooks/DataSet/Cars/SerialData/X_training'
print(os.path.getsize(A))
if os.path.getsize(A):
  with open(A, 'rb') as M:
    Unpicker = pickle.load(M)


81440157
---------------------------------------------------------------------------

EOFError                                  Traceback (most recent call last)
<ipython-input-29-a42d4284bb80> in <module>
      3 if os.path.getsize(A):
      4   with open(A, 'rb') as M:
----> 5     Unpicker = pickle.load(M)

EOFError: Ran out of input
0

There are 0 best solutions below