how to handle ever-changing password in sqlalchemy+psycopg2?

有些话、适合烂在心里 提交于 2019-12-05 18:46:44

One approach would be to use the creator argument of create_engine():

creator – a callable which returns a DBAPI connection. This creation function will be passed to the underlying connection pool and will be used to create all new database connections. Usage of this function causes connection parameters specified in the URL argument to be bypassed.

Just modify your make_sqlalchemy_string() to produce the dsn argument for psycopg2.connect(), which might mean not having to modify it at all due to accepted connection string formats, and pass the creator:

create_engine('postgresql://', creator=lambda: psycopg2.connect(make_dsn_string()))
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!