Why Do I Get "Pickle - Eoferror: Ran Out of Input" Reading an Empty File

Why do I get Pickle - EOFError: Ran out of input reading an empty file?

I would check that the file is not empty first:

import os

scores = {} # scores is an empty dict already

if os.path.getsize(target) > 0:
with open(target, "rb") as f:
unpickler = pickle.Unpickler(f)
# if file is not empty scores will be equal
# to the value unpickled
scores = unpickler.load()

Also open(target, 'a').close() is doing nothing in your code and you don't need to use ;.

Dealing with EOFError: Ran out of input error from file that is constantly updated

To answer your question about 20 tries, you can use a loop. Make sure to catch the specific exception, in case a different error is thrown.

for i in range(20):
try:
df = pd.read_pickle('data')
except EOFError:
time.sleep(0.5)

EOFError: Ran out of input and file im trying to pickle is not empty

Working example:

import pickle

password_input = '123123123'
pickle_out = open("steam_password.pickle","wb")
pickle.dump(password_input, pickle_out)
pickle_out.close()

pickle_inn = open('steam_password.pickle','rb')
password = pickle.load(pickle_inn)

pickle_out.close just makes reference to function, don't calls it

And it's definetly bad idea to store password in pickle file. You can store it as md5 hash:

import hashlib

password = '123123123'
hashlib.md5(password.encode('utf8')).hexdigest()


Related Topics



Leave a reply



Submit