これは私の最初の投稿です。エラーが発生しています:
Traceback (most recent call last): File "<input>", line 1, in <module> File "intruder.py", line 47, in <module> main() File "intruder.py", line 16, in main readfile() File "intruder.py", line 34, in readfile pickle.load(f) File "/usr/lib/python2.7/pickle.py", line 1378, in load return Unpickler(file).load() File "/usr/lib/python2.7/pickle.py", line 858, in load dispatch[key](self) File "/usr/lib/python2.7/pickle.py", line 880, in load_eof raise EOFError EOFError
コードの場合:
#!/usr/bin/python
import getpass
import bz2
import pickle
import marshal
import os, sys
global data
global firsttime
global password
global user
fp = open("firsttime.txt", "r")
data = fp.read();
firsttime = data
def main():
readfile()
name = raw_input('What is your name? ')
if name == user:
user_input = getpass.getpass('Enter Password: ')
if user_input != password:
print "Intruder alert!"
main()
if name != user:
print "Intruder alert!"
main()
print "Login Successful! "
def savefile():
n = open("settings.pkl", 'wb')
pickle.dump(user, n, 2)
pickle.dump(password, n, 2)
n.close()
def readfile():
f = open("settings.pkl", "rb")
pickle.load(f)
f.close()
if data < 1:
user = raw_input ("Enter desired username: ")
password = getpass.getpass('Enter desired password: ')
# encrypted_password = bz2.compress(password)
# bz2.decompress(encrypted_password)
data = 2
g = open("firsttime.txt", "rb")
outf.write(g(data))
g.close()
savefile()
if data > 1:
main()
編集:上記の問題を修正しました。私が変更され:
fp = open("firsttime.txt", "r")
に:
fp = file("firsttime.txt", "r")
そして今、それはエラーを示しています:
Traceback (most recent call last):
File "intruder.py", line 47, in <module>
main()
File "intruder.py", line 17, in main
if name == user:
NameError: global name 'user' is not defined
user はユーザーの raw_input として定義されており、このエラーが表示される直前に入力を求められるため、これは奇妙です。