运行相同. py脚本本身可以成功工作,但在html中会出现错误
环境:在visual studio代码上打开live服务器以运行. html
<html>
<head>
<link rel="stylesheet" href="https://pyscript.net/latest/pyscript.css" />
<script defer src="https://pyscript.net/latest/pyscript.js"></script>
</head>
<body>
<b><p>this is the info from sql</p></b>
<br>
<py-config>
packages = ["mysql"]
</py-config>
<py-script >
import mysql.connector
import webbrowser
import time
import pymysql
mydb = mysql.connector.connect(
host="196.168.101.141",
user="root",
password="password123",
database="cool_db",
auth_plugin='mysql_native_password'
)
mycursor = mydb.cursor()
mycursor.execute("SELECT P_TITLE,P_DESC FROM webpage WHERE P_ID = 'en_1-01'")
myresult = mycursor.fetchall()
print(myresult)
</py-script>
</body>
</html>
- 错误讯息
(PY1001): Unable to install package(s) 'mysql'. Reason: Can't find a pure Python 3 Wheel for package(s) 'mysql'. See: https://pyodide.org/en/stable/usage/faq.html#micropip-can-t-find-a-pure-python-wheel for more information.
- 问题:浏览器中的PyScript(Pyodide + WASM +...)能否连接到SQL服务器?**
1.如果可以,我该怎么改正呢?
1.如果没有,我该如何做才能达到同样的目标
1条答案
按热度按时间p3rjfoxz1#
对于问题2:
参见Datasette Lite-“使用WebAssembly和Pyodide在浏览器中运行的数据集”
更接近你所寻找的,我看到有一个'加载SQLite数据库'部分和'用SQL初始化'部分.另外,我看到'Live tool' version有一个按钮'加载SQL',让你“输入一个完整的URL到一个SQL文件”.
有关详细信息,请访问:
Datasette Lite: a server-side Python web application running in a browser