目标: 网页能显示 mysql 其中几项栏位的资料
已经成功写出相关的.py 脚本了
相同的 .py 脚本本身运行成功,但在 html 中出现错误
环境:在visual studio code上打开live server运行.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>
this is the info from sql
<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>
- 错误信息error message
(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.
Question: 浏览器中的 PyScript (Pyodide + WASM + ...) 可以连接到 SQL 服务器吗?
- 如果可以,我该如何改正它?
- 如果不行,我该怎么做才能达到同样的目标/效果