我正在尝试弄清楚如何在 create_engine()
中设置连接超时,到目前为止我已经尝试过:
create_engine(url, timeout=10)
TypeError: Invalid argument(s) 'timeout' sent to create_engine(), using configuration PGDialect_psycopg2/QueuePool/Engine. Please check that the keyword arguments are appropriate for this combination of components.
create_engine(url, connection_timeout=10)
TypeError: Invalid argument(s) 'connection_timeout' sent to create_engine(), using configuration PGDialect_psycopg2/QueuePool/Engine. Please check that the keyword arguments are appropriate for this combination of components.
create_engine(db_url, connect_args={'timeout': 10})
(psycopg2.OperationalError) invalid connection option "timeout"
create_engine(db_url, connect_args={'connection_timeout': 10})
(psycopg2.OperationalError) invalid connection option "connection_timeout"
create_engine(url, pool_timeout=10)
我该怎么办?
最佳答案
正确的方式是这个(connect_timeout
而不是connection_timeout
):
create_engine(db_url, connect_args={'connect_timeout': 10})
...它适用于 Postgres 和 MySQL
ps:(超时以秒为单位)
关于python - 如何在 SQLAlchemy 中设置连接超时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35640726/