From 06ca4bd875448e8e71ad5fc2e467c20bba774caa Mon Sep 17 00:00:00 2001 From: lihangfu Date: Fri, 11 Oct 2024 18:08:46 +0800 Subject: [PATCH] fix: 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)