数据库连接URI中密码存在特殊字符
今天在用sqlalchemy创建mysql engine时报错from sqlalchemy import create_engineengine = create_engine(f'mysql+pymysql://{user}:{password}@{address}:{port}/{database}', pool_size=2000, max_overflow=0)原来是用因为passwor
·
今天在用sqlalchemy创建mysql engine时报错
from sqlalchemy import create_engine
engine = create_engine(f'mysql+pymysql://{user}:{password}@{address}:{port}/{database}', pool_size=2000, max_overflow=0)
原来是用因为password中存在“@”或“:”等特殊字符
使用URL编码即可解决
import urllib
from sqlalchemy import create_engine
engine = create_engine(f'mysql+pymysql://{user}:{urllib.parse.quote_plus(password)}@{address}:{port}/{database}', pool_size=2000, max_overflow=0)
更多推荐
已为社区贡献1条内容
所有评论(0)