Forums

Error running Telethon bot script on "Always on Task": Unable to open database file

I'm having trouble running an "Always-on tasks" process with a Python script that starts a bot using the Telethon library. To execute the script, I'm using the following command:

source virtualenvwrapper.sh && workon myvirtualenv && chmod 777 /home/massimocascone/WellnessCommunitybot/script.py && python3.10 /home/massimocascone/WellnessCommunitybot/script.py

However, when I run it, I receive an error message that reads:

Mar 17 19:47:51 Traceback (most recent call last):
Mar 17 19:47:51   File "/home/massimocascone/WellnessCommunitybot/script.py", line 11, in <module>
Mar 17 19:47:51     client = TelegramClient(config.session_name_bot, config.API_ID, config.API_HASH).start(bot_token=config.BOT_TOKEN)
Mar 17 19:47:51   File "/home/massimocascone/.virtualenvs/myvirtualenv/lib/python3.10/site-packages/telethon/client/telegrambaseclient.py", line 275, in __init__
Mar 17 19:47:51     session = SQLiteSession(session)
Mar 17 19:47:51   File "/home/massimocascone/.virtualenvs/myvirtualenv/lib/python3.10/site-packages/telethon/sessions/sqlite.py", line 47, in __init__
Mar 17 19:47:51     c = self._cursor()
Mar 17 19:47:51   File "/home/massimocascone/.virtualenvs/myvirtualenv/lib/python3.10/site-packages/telethon/sessions/sqlite.py", line 242, in _cursor
Mar 17 19:47:51     self._conn = sqlite3.connect(self.filename,
Mar 17 19:47:51 sqlite3.OperationalError: unable to open database file

Can someone assist me with resolving this issue?

It looks like telethon is trying to use a database but for some reason it can't open it -- maybe check in the documentation for how to set up this. Also, a hint, when you're developing an always-on task script, I'd suggest using Bash console first, because it's much faster and you can add breakpoints, etc., to debug the code.

Hello, thank you for your response. The problem is that when i execute the command:

python3.10 /home/massimocascone/WellnessCommunitybot/script.py

on a bash console everything goes well, and the problem does not happen. I found out that maybe the script.py does not have writing permission to create the file session file that telethon needs to work, but i used the chmod command with 777 so it should work...

Do you know where it's looking for the database? Can you configure that?