我写了一个 .py 脚本可以提取 mysql 数据并打print出来,我想让 html 页面运行这个python脚本但遇到mysql.connector.errors.InterfaceError,可是 .py 脚本单独工作正常
环境:我将 .py 和 .html 都放在 winSCP 中使往页生效
- get_sql_where.py(脚本本身可以正常执行,我在 cmd 中运行 get_sql_where.py 运行正常)
import mysql.connector
import webbrowser
import time
import pymysql
mydb = mysql.connector.connect(
host="196.168.1.141",
user="root",
password="password123",
database="normal_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)
- .html page
<!DOCTYPE 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-connector-python", "PyMySQL"]
</py-config>
<py-script src="./get_sql_where.py" />
</body></html>
主要问题:遇到 mysql.connector.errors.InterfaceError: 2003
- 错误信息error message
Traceback (most recent call last):
File "/lib/python3.10/site-packages/mysql/connector/network.py", line 600, in open_connection
self.sock.connect(sockaddr)
BlockingIOError: [Errno 26] Operation in progress
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/lib/python3.10/site-packages/_pyodide/_base.py", line 435, in eval_code
.run(globals, locals)
File "/lib/python3.10/site-packages/_pyodide/_base.py", line 304, in run
coroutine = eval(self.code, globals, locals)
File "<exec>", line 9, in <module>
File "/lib/python3.10/site-packages/mysql/connector/pooling.py", line 294, in connect
return MySQLConnection(*args, **kwargs)
File "/lib/python3.10/site-packages/mysql/connector/connection.py", line 167, in __init__
self.connect(**kwargs)
File "/lib/python3.10/site-packages/mysql/connector/abstracts.py", line 1178, in connect
self._open_connection()
File "/lib/python3.10/site-packages/mysql/connector/connection.py", line 571, in _open_connection
self._socket.open_connection()
File "/lib/python3.10/site-packages/mysql/connector/network.py", line 602, in open_connection
raise InterfaceError(
mysql.connector.errors.InterfaceError: 2003: Can't connect to MySQL server on '196.168.1.141:3306' (26 Operation in progress)
我非常努力地想实现这个目标,希望有人能帮忙一下