目标: 网页能显示 mysql 其中几项栏位的资料
已经成功写出相关的.py 脚本了
相同的 .py 脚本本身运行成功,但在 html 中出现错误
环境:在visual studio code上打开live server运行.html
this is the info from sql
packages = ["mysql"]
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)
(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 服务器吗?
PyScript 在浏览器中是可以通过 SQL 驱动程序连接到 SQL 服务器的,但是你遇到的错误 "Unable to install package(s) 'mysql'. Reason: Can't find a pure Python 3 Wheel for package(s) 'mysql'" 是因为 PyScript 当前的版本不支持 mysql 模块,无法安装。
你可以尝试使用其他的 Python SQL 驱动程序,例如 PyMySQL,它是可以工作的。