在 python 问题中从 SQLalchemy 连接到 Synology NAS 上的 MariaDB 数据库
Connect to MariaDB database on Synology NAS from SQLalchemy in python issue
进一步深化我的问题 here,我试图以更简单的方式提出这个问题。
按照本教程,我正在尝试使用 SQLalchemy 远程启动到我 NAS 中的 Mariadb 数据库的连接。这是代码:
# Module Imports
import mariadb
import sys
user = "my_name"
passwd = "my_pass"
host = "192.168.1.111"
db = "test"
port= "3307"
# Connect to MariaDB Platform
try:
conn = mariadb.connect(
user=user,
password=passwd,
host=host,
port=3307,
database=db
)
except mariadb.Error as e:
print(f"Error connecting to MariaDB Platform: {e}")
sys.exit(1)
# Get Cursor
cur = conn.cursor()
然后我得到这个错误:
ERROR:root:Internal Python error in the inspect module.
Below is the traceback from this internal error.
Error connecting to MariaDB Platform: Can't connect to server on '192.168.1.111' (36)
Traceback (most recent call last):
File "/var/folders/r5/wq0wq8mx0d56rbrbs38jt94w0000gn/T/ipykernel_39174/3834131737.py", line 14, in <module>
conn = mariadb.connect(
mariadb.OperationalError: Can't connect to server on '192.168.1.111' (36)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/user/miniforge3/lib/python3.9/site-packages/IPython/core/interactiveshell.py", line 3444, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "/var/folders/r5/wq0wq8mx0d56rbrbs38jt94w0000gn/T/ipykernel_39174/3834131737.py", line 24, in <module>
sys.exit(1)
SystemExit: 1
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/user/miniforge3/lib/python3.9/site-packages/IPython/core/ultratb.py", line 1101, in get_records
return _fixed_getinnerframes(etb, number_of_lines_of_context, tb_offset)
File "/Users/user/miniforge3/lib/python3.9/site-packages/IPython/core/ultratb.py", line 248, in wrapped
return f(*args, **kwargs)
File "/Users/user/miniforge3/lib/python3.9/site-packages/IPython/core/ultratb.py", line 281, in _fixed_getinnerframes
records = fix_frame_records_filenames(inspect.getinnerframes(etb, context))
File "/Users/user/miniforge3/lib/python3.9/inspect.py", line 1541, in getinnerframes
frameinfo = (tb.tb_frame,) + getframeinfo(tb, context)
AttributeError: 'tuple' object has no attribute 'tb_frame'
我已经安装了 brew mariadb-connector-cand ;
brew 安装了 mariadb;和
pip 安装 PyMySQL。
有人愿意帮忙吗?
我赞同@Tim Roberts。转到您的 NAS“已安装包”,单击 MariaDB 10 应用程序。在其中请确保数据库可通过 Intranet 或 Internet 共享。它被称为 TCP/IP 连接。检查它,您的连接将正常工作。
这是很多人在第一次启动 Mariadb 时忘记的一点。
进一步深化我的问题 here,我试图以更简单的方式提出这个问题。
按照本教程,我正在尝试使用 SQLalchemy 远程启动到我 NAS 中的 Mariadb 数据库的连接。这是代码:
# Module Imports
import mariadb
import sys
user = "my_name"
passwd = "my_pass"
host = "192.168.1.111"
db = "test"
port= "3307"
# Connect to MariaDB Platform
try:
conn = mariadb.connect(
user=user,
password=passwd,
host=host,
port=3307,
database=db
)
except mariadb.Error as e:
print(f"Error connecting to MariaDB Platform: {e}")
sys.exit(1)
# Get Cursor
cur = conn.cursor()
然后我得到这个错误:
ERROR:root:Internal Python error in the inspect module.
Below is the traceback from this internal error.
Error connecting to MariaDB Platform: Can't connect to server on '192.168.1.111' (36)
Traceback (most recent call last):
File "/var/folders/r5/wq0wq8mx0d56rbrbs38jt94w0000gn/T/ipykernel_39174/3834131737.py", line 14, in <module>
conn = mariadb.connect(
mariadb.OperationalError: Can't connect to server on '192.168.1.111' (36)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/user/miniforge3/lib/python3.9/site-packages/IPython/core/interactiveshell.py", line 3444, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "/var/folders/r5/wq0wq8mx0d56rbrbs38jt94w0000gn/T/ipykernel_39174/3834131737.py", line 24, in <module>
sys.exit(1)
SystemExit: 1
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/user/miniforge3/lib/python3.9/site-packages/IPython/core/ultratb.py", line 1101, in get_records
return _fixed_getinnerframes(etb, number_of_lines_of_context, tb_offset)
File "/Users/user/miniforge3/lib/python3.9/site-packages/IPython/core/ultratb.py", line 248, in wrapped
return f(*args, **kwargs)
File "/Users/user/miniforge3/lib/python3.9/site-packages/IPython/core/ultratb.py", line 281, in _fixed_getinnerframes
records = fix_frame_records_filenames(inspect.getinnerframes(etb, context))
File "/Users/user/miniforge3/lib/python3.9/inspect.py", line 1541, in getinnerframes
frameinfo = (tb.tb_frame,) + getframeinfo(tb, context)
AttributeError: 'tuple' object has no attribute 'tb_frame'
我已经安装了 brew mariadb-connector-cand ; brew 安装了 mariadb;和 pip 安装 PyMySQL。
有人愿意帮忙吗?
我赞同@Tim Roberts。转到您的 NAS“已安装包”,单击 MariaDB 10 应用程序。在其中请确保数据库可通过 Intranet 或 Internet 共享。它被称为 TCP/IP 连接。检查它,您的连接将正常工作。
这是很多人在第一次启动 Mariadb 时忘记的一点。