Search code examples
pythonpython-3.xpicklepyautogui

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


import pyautogui
import pickle

username = input("Enter your steam username: ")
pickle_out = open("steam.pickle","wb")
pickle.dump(username, pickle_out)
pickle_out.close


password_input = input("Enter your password: ")
password_test = input("Enter your password again: ")

if password_input == password_test :
    pickle_out = open("steam_password.pickle","wb")
    pickle.dump(password_input, pickle_out)
    pickle_out.close
else:
    print("The passwords don't match.")


def login():
    pyautogui.click(x=1165, y=634)
    pickle_in = open('steam.pickle','rb')
    username = pickle.load(pickle_in)
    pyautogui.typewrite(username)
    pyautogui.click(x=1162, y=669)
    pickle_inn = open('steam_password.pickle','rb')
    password = pickle.load(pickle_inn)
    pyautogui.typewrite(password)


login()


def remember():
    remember_or = input("Do you want to remember your password? (y/n) ")
    if remember_or == 'y':
        pyautogui.click(x=1163, y=697)
        pyautogui.click(x=1185, y=730)


remember()


def get_position():
    position_start = input()
    if position_start == 'm':
        print(pyautogui.position())

The error that I get is

Traceback (most recent call last):
  File "c:/Users/c/Desktop/Programming/Python/passwordsaver.py", line 32, in <module>
    login()
  File "c:/Users/c/Desktop/Programming/Python/passwordsaver.py", line 28, in login
    password = pickle.load(pickle_inn)
EOFError: Ran out of input

I checked what this error could mean and found out that it could mean that the file that i'm trying to pickle is empty but I checked and it isnt empty. I tried changing variable names as I thought that it had something to do with the code. Any help will be appreciated!


Solution

  • 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()