sqlite3.OperationalError: database is locked
ForelliCH opened this issue · comments
Code that causes the issue
`from telethon import TelegramClient
import json
import os
from tw_func import *
tw_filename = "tw_crwlr_prd.py"
tw_filename = os.path.basename(file)[:-3]
tw_function_crwlr_workdir(tw_filename)
with open("tw_conf.json", 'r') as f:
tw_conf = json.load(f)
api_id = "xxxxxxx"
api_hash = "xxxxxxxxxxx"
tw_telclient = TelegramClient("tw_crwlr_telegram", api_id, api_hash)
group_name = "gemcomm"
async def save_messages():
await tw_telclient.start()
messages = await tw_telclient.get_messages(group_name, limit=10)
tw_data = ""
for message in messages:
tw_data += f"{message.sender_id}: {message.text}\n\n"
await tw_telclient.disconnect()
return tw_data
with tw_telclient:
tw_data = tw_telclient.loop.run_until_complete(save_messages())
print(tw_data)`
Expected behavior
I have a development environment with Windows 10 and Python 3.8 where I tested the code. It works without any issues. Then, I exported the script to a Linux (Ubuntu 20.04.6 LTS) environment with Python 3.8. There, the aforementioned error occurred immediately. In the new environment, there was no session file present; it was completely new. I then tested with Linux (Ubuntu 23.10) and Python 3.11 as well. Same problem.
Actual behavior
The error message appears. By the way, the session file remains 0KB in size. It doesn't seem like anything is being written to it. I then gave one of these 0KB files full permissions (777), but that didn't help either. The existing entries are unfortunately not helpful. It is indeed a new system, with no open processes.
Traceback
tw_telclient = TelegramClient('tw_crwlr_telegram', api_id, api_hash) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/tw_admin/.local/lib/python3.11/site-packages/Telethon-1.34.0-py3.11.egg/telethon/client/telegrambaseclient.py", line 290, in __init__ File "/home/tw_admin/.local/lib/python3.11/site-packages/Telethon-1.34.0-py3.11.egg/telethon/sessions/sqlite.py", line 71, in __init__ File "/home/tw_admin/.local/lib/python3.11/site-packages/Telethon-1.34.0-py3.11.egg/telethon/sessions/sqlite.py", line 162, in _create_table sqlite3.OperationalError: database is locked
tw_telclient = TelegramClient('tw_crwlr_telegram', api_id, api_hash) File "/usr/local/lib/python3.8/dist-packages/telethon/client/telegrambaseclient.py", line 289, in __init__ session = SQLiteSession(session) File "/usr/local/lib/python3.8/dist-packages/telethon/sessions/sqlite.py", line 71, in __init__ self._create_table( File "/usr/local/lib/python3.8/dist-packages/telethon/sessions/sqlite.py", line 162, in _create_table c.execute('create table {}'.format(definition)) sqlite3.OperationalError: database is locked
Telethon version
1.34.0
Python version
3.8 / 3.11
Operating system (including distribution name and version)
Ubuntu 20.04.6 / Ubuntu 23.10
Other details
No response
Checklist
- The error is in the library's code, and not in my own.
- I have searched for this issue before posting it and there isn't an open duplicate.
- I ran
pip install -U https://github.com/LonamiWebs/Telethon/archive/v1.zip
and triggered the bug in the latest version.
This is unlikely to be a problem in the library https://docs.telethon.dev/en/stable/quick-references/faq.html#sqlite3-operationalerror-database-is-locked.