From ef71cf18c95d9791609c30aae58b2e895c60632a Mon Sep 17 00:00:00 2001 From: lihangfu <280001404@qq.com> Date: Sat, 12 Oct 2024 11:29:49 +0800 Subject: [PATCH] sqlalchemy password coding --- python/sqlalchemy/example.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/python/sqlalchemy/example.py b/python/sqlalchemy/example.py index e00a632..6c98c5f 100644 --- a/python/sqlalchemy/example.py +++ b/python/sqlalchemy/example.py @@ -1,4 +1,5 @@ #!/usr/bin/python3 +from urllib.parse import quote_plus from sqlalchemy import create_engine, Column, Integer, VARCHAR from sqlalchemy.orm import sessionmaker from sqlalchemy.ext.declarative import declarative_base @@ -12,7 +13,7 @@ # 创建一个 SQLAlchemy 引擎,连接到 OceanBase 数据库 # 创建数据库连接字符串 -connection_string = f'mysql+pymysql://{username}:{password}@{host}:{port}/{database}' +connection_string = f'mysql+pymysql://{username}:{quote_plus(password)}@{host}:{port}/{database}' # 创建SQLAlchemy引擎 engine = create_engine(connection_string)