You cannot pass a dictionary straight into create_engine()
as a substitute for the url, however you can pass a sqlalchemy.engine.url.URL
object which can be instantiated easily with a dict
.
From the docs:
This object is suitable to be passed directly to a create_engine()
call.
For example:
from sqlalchemy.engine.url import URL
config = dict(
drivername='driver',
username='username',
password='qwerty1',
host='127.0.0.1',
port='5000',
database='mydb',
query={'encoding': 'utf-8'}
)
url = URL(**config)
print(url) # driver://username:qwerty1@127.0.0.1:5000/mydb?encoding=utf-8
engine = create_engine(URL, echo=True)
However, the issues you are having with passing in a string formatted URL aren't likely to be a SQLAlchemy problem as the string formatting would take place before create_engine()
gets it's hands on the string. Unfortunately your question doesn't include an example that reproduces the exact problem you are having, so I cannot say much more than that.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…