Вот проблема
for record in reader:
if record[0] == username:
continue
else:
exit()
Вы, вероятно, ошибаетесь в использовании exit()
и continue
. Функция exit
обычно вызывается, когда вы хотите выйти из интерактивного режима python, и вызывает исключение SystemExit
(в этом случае вы вызываете выход из вашей программы). continue
с другой стороны говорит Python перейти к следующему шагу в цикле.
Вы, вероятно, хотите сделать что-то вроде этого:
for record in reader:
if record[0] == username:
# Handle authenticated users here
print("Login successful")
return # exit the function
# Handle unauthenticated users here
print("User not found")
Вам также следует подумать о заменеваш файл открывается и закрывается с помощью контекстных менеджеров. Вместо:
my_file = open("some-file", "r")
# read some input from the file
my_file.close()
# ...
my_file = open("some-file", "w")
# write some output to the file
my_file.close()
используйте:
with open("some-file", "r") as my_file:
# read my_file in here
# ...
with open("some-file", "w") as my_file:
# write to my_file in here
Таким образом python пытается закрыть ваш файл, даже если на пути встречается исключение.