Зачем получать sqlite3.OperationalError? - PullRequest
0 голосов
/ 01 мая 2020

Я изучаю python уже месяц и пытаюсь запустить несколько собственных проектов. В настоящее время я создаю простое приложение, которое хранит пароли.

Я использую Tkinter & SQlite3. Теперь, пытаясь проверить, если имя пользователя уже есть, я получаю эту ошибку - sqlite3.OperationalError: база данных заблокирована

Есть мысли о том, как я могу улучшить код?

Спасибо!

def create_account():
  """"
      First check if there is an account, in case there is one already with the same username
      print "There is already an account with the same username".
      Otherwise, create a new account.
  """
  username = username_input.get()
  password = password_input.get()

  cursor.execute("""SELECT username FROM login""")
  db_username = cursor.fetchall()
  user_list = []

  for row in db_username:
      for i in row:
          user_list.append(i)
  if username in user_list:
      print('There is already an account with this username. Choose a different username')
  else:
      cursor.execute("""
                          INSERT INTO login (username, password)
                          VALUES (? , ?)
                      """, (username, password))
      print('New Account Created')
      cursor.connection.commit()

  username_input.delete(0, "end")
  password_input.delete(0, "end")

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...