gpt4 book ai didi

python - 如何在 SQLAlchemy 中设置连接超时

转载 作者:IT老高 更新时间:2023-10-28 20:52:46 30 4
gpt4 key购买 nike

我正在尝试弄清楚如何在 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

docs sqlalchemy connect-args

ps:(超时以秒为单位)

关于python - 如何在 SQLAlchemy 中设置连接超时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35640726/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com