I am trying to create a telegram bot and used code from github. I had a few issues earlier which are finally solved but can't seem to find a solution for this.
This is the error I see:
self.conn = sqlite3.connect(str(path), timeout=1, check_same_thread=False) sqlite3.OperationalError: unable to open database file
Traceback (most recent call last):
File "G:\Spotify Downloader\mbot\__main__.py", line 30, in <module>
Mbot().run()
File "G:\Spotify Downloader\venv\lib\site-packages\pyrogram\methods\utilities\run.py", line 80, in run
run(self.start())
File "G:\Python\lib\asyncio\base_events.py", line 646, in run_until_complete
return future.result()
File "G:\Spotify Downloader\mbot\__init__.py", line 76, in start
await super().start()
File "G:\Spotify Downloader\venv\lib\site-packages\pyrogram\methods\utilities\start.py", line 58, in start
is_authorized = await self.connect()
File "G:\Spotify Downloader\venv\lib\site-packages\pyrogram\methods\auth\connect.py", line 40, in connect
await self.load_session()
File "G:\Spotify Downloader\venv\lib\site-packages\pyrogram\client.py", line 562, in load_session
await self.storage.open()
File "G:\Spotify Downloader\venv\lib\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
Here is the file of code where error is located:
import logging
import os
import sqlite3
from pathlib import Path
from .sqlite_storage import SQLiteStorage
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)
Please could someone find the issue here...