解决使用sqlalchemy时MySQL密码含有特殊字符问题

前言

当MySQL密码中含有特殊字符时,使用sqlalchemy大概率连不上,这时候就需要from urllib.parse import quote_plus as urlquote

示例代码

from sqlalchemy import create_engine
from urllib.parse import quote_plus as urlquote

mysql_password = "!@#$%^&*()"
eng = create_engine(f"mysql+pymysql://myuser:{urlquote(mysql_password)}@127.0.0.1:3306/dbtest")
posted @ 2022-02-09 13:56  花酒锄作田  阅读(1592)  评论(0编辑  收藏  举报