failed to open database file (Pyscript sqlite3)

Viewed 381

I recently started using Py-script for my HTML documents and run into an Error on which , due to the lack of questions on py-script, i couldnt find a solution by researching.

The error message is as following:

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 )

I don't know what's the issue , because while running the program normally in python everything works as intended. I tried giving all needed files all permissions(chmod 777), which solved nothing. Thanks for your help in advance.

    <!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>


1 Answers

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.

Related