简体   繁体   English

无法打开数据库文件(Pyscript sqlite3)

[英]failed to open database file (Pyscript sqlite3)

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.我最近开始对我的 HTML 文档使用 Py-script 并遇到一个错误,由于 py-script 缺乏问题,我无法通过研究找到解决方案。

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.我不知道是什么问题,因为在 python 中正常运行程序时,一切都按预期工作。 I tried giving all needed files all permissions(chmod 777), which solved nothing.我尝试为所有需要的文件提供所有权限(chmod 777),但没有解决任何问题。 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>


Pyscript has the same restrictions that JavaScript has when running in the browser. Pyscript 具有与 JavaScript 在浏览器中运行时相同的限制。 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.在您的情况下,您尝试直接访问位于本地文件系统上的 sqlite3 数据库文件。 That is not possible in Pyscript or JavaScript running inside a browser.这在浏览器中运行的 Pyscript 或 JavaScript 中是不可能的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM