Search code examples
telegram-botpython-telegram-bottelethon

Telethon Issue: OperationalError: database is locked


The issue was appearing because we're connecting the client twice in the code.

client = TelegramClient(phone, api_id, api_hash)

client.connect()
if not client.is_user_authorized():
    client.send_code_request(phone)
    client.sign_in(phone, input('Enter the code: '))

Solution

  • To solve the "DataBase is locked" error,

    you'll have to restart/abort the kernal and then remove the already created session from your local directory. Remove the client.connect() line from the code as it's getting connected at the first line itself.

    The session file must be created with the following name as {phone}.session in the directory where your python code is kept.