Using PyScript in my HTML documents I run into an error:
JsException(PythonError: Traceback (most recent call last):
File "/lib/python3.10/site-packages/_pyodide/_base.py", line 429,
in eval_code .run(globals, locals)
File "/lib/python3.10/site-packages/_pyodide/_base.py", line 300,
in run coroutine = eval(self.code, globals, locals)
File "", line 3,
in sqlite3.OperationalError: unable to open database file )
When running the program in Python it works. I gave needed files all permissions (chmod 777) which solved nothing.
<!DOCTYPE html>
<html lang="">
<head>
<meta charset="utf-8">
<script defer src="https://pyscript.net/alpha/pyscript.js"></script>
<style>
#Ausgabe {
background-color: red;
}
</style>
<py-env>
-sqlite3
</py-env>
</head>
<body>
<main>
<textarea id="Ausgabe"> </textarea>
</main>
<py-script>
import sqlite3
#opening the database
connecting= "home/marcel/Schreibtisch/Studium/JustForFun/Betrag.db"
connection = sqlite3.connect(connecting)
cursor = connection.cursor()
#executing the connection and printing each row in the db
sql = "SELECT * FROM personen "
cursor.execute(sql)
connection.commit()
for dsatz in cursor:
ausgab= dsatz[0] + " " + dsatz[1] + " " + dsatz[2]
pyscript.write("Ausgabe",ausgab)
connection.close()
</py-script>
</body>
</html>
Pyscript has the same restrictions that JavaScript has when running in the browser. No local file access, no sockets, nothing that tries to escape out of the browser sandbox.
In your case, you are trying to directly access a sqlite3 database file located on the local file systems. That is not possible in Pyscript or JavaScript running inside a browser.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With