Forums

Pyrogram cannot find or create sqlite3 file

Hello! I was trying to run my userbot here, but it raises an error:

File "/home/SinYaYaSoVa/.local/lib/python3.10/site-packages/pyrogram/storage/file_storage.py", line 58, in open self.conn = sqlite3.connect(str(path), timeout=1, check_same_thread=False) sqlite3.OperationalError: unable to open database file

If I go through the path I cannot find a directory named storage there. However, on my IDE (in venv) there is the directory and the file named file_storage.py

Did I install pyrogram wrong or there have to be something with sqlite?

Do you know where it's getting the path variable (the location of the SQLite file) from? Is that something you've configured the library with?

giles, no, I don't know. I did only run IDE, created venv there, downloaded every lib I via pip and that's it. May it be related to the venv? Because I didn't move it here, I just installed the requirement libs via console here.

It's about your database file, not where packages are installed. What is the content of path variable in file_storage.py?

fjl,

log = logging.getLogger(__name__)

class FileStorage(SQLiteStorage): FILE_EXTENSION = ".session"

def __init__(self, name: str, workdir: Path):
    super().__init__(name)

    self.database = workdir / (self.name + self.FILE_EXTENSION)

def update(self):
    version = self.version()

    if version == 1:
        with self.lock, self.conn:
            self.conn.execute("DELETE FROM peers")

        version += 1

    if version == 2:
        with self.lock, self.conn:
            self.conn.execute("ALTER TABLE sessions ADD api_id INTEGER")

        version += 1

    self.version(version)

async def open(self):
    path = self.database
    file_exists = path.is_file()

    self.conn = sqlite3.connect(str(path), timeout=1, check_same_thread=False)

    if not file_exists:
        self.create()
    else:
        self.update()

    with self.conn:
        try:  # Python 3.6.0 (exactly this version) is bugged and won't successfully execute the vacuum
            self.conn.execute("VACUUM")
        except sqlite3.OperationalError:
            pass

async def delete(self):
    os.remove(self.database)

OK, so the variable path is being set from the field self.database. Are you doing anything to set that?

giles, No, I do nothing with that

What is workdir ?

fjl, I assume that is the main directory where the the main python file is executed. The sql file with extension .session is being created when you launch the py file and the bot gets the authorisation from Telegram. All this info is stored in this particular file.

Is it possible to upload my venv and use it? Maybe it will work.

Make sure that workdir in that code is an absolute path: https://help.pythonanywhere.com/pages/NoSuchFileOrDirectory/

No, virtualenvs are not, generally, portable between machines.

Okey, thank you so much. I'll try to fix all this!