修复:IoT数据库连接支持mysql-connector-python驱动
腾讯云MySQL需要use_pure+ssl_disabled参数才能认证通过, 当URL使用mysqlconnector驱动时自动添加connect_args
This commit is contained in:
@@ -109,11 +109,16 @@ def get_iot_engine():
|
|||||||
iot_url = settings.iot_database_url
|
iot_url = settings.iot_database_url
|
||||||
if not iot_url:
|
if not iot_url:
|
||||||
raise RuntimeError("IOT_DATABASE_URL 未配置,无法连接 IoT 数据库")
|
raise RuntimeError("IOT_DATABASE_URL 未配置,无法连接 IoT 数据库")
|
||||||
|
# mysql+mysqlconnector 需要 connect_args 传递认证参数
|
||||||
|
connect_args = {}
|
||||||
|
if "mysqlconnector" in iot_url:
|
||||||
|
connect_args = {"use_pure": True, "ssl_disabled": True}
|
||||||
_iot_engine = create_engine(
|
_iot_engine = create_engine(
|
||||||
iot_url,
|
iot_url,
|
||||||
echo=False,
|
echo=False,
|
||||||
pool_recycle=1800,
|
pool_recycle=1800,
|
||||||
pool_pre_ping=True,
|
pool_pre_ping=True,
|
||||||
|
connect_args=connect_args,
|
||||||
)
|
)
|
||||||
logger.info(f"IoT 数据库引擎已创建")
|
logger.info(f"IoT 数据库引擎已创建")
|
||||||
return _iot_engine
|
return _iot_engine
|
||||||
|
|||||||
Reference in New Issue
Block a user