可以捕获连接错误点击室DB API
我正在尝试使用Python中的Clickhouse-Driver DB API连接到KX时捕获连接错误。但是由于某种原因,尝试:块通过没有错误的情况,而我没有例外
def __enter__(self):
try:
self.connector = db.connect(dsn=self.connection_string)
except Error as e: # pass
self.error = str(e)[:250]
self.connector = None
return self
,并且仅在执行执行
sql时才会发生错误。在连接时有什么方法可以遇到连接错误?
I'm trying to catch a connection error when connecting to kx using the clickhouse-driver db api in python. But for some reason, the try: block passes without errors, and I don't get exception
def __enter__(self):
try:
self.connector = db.connect(dsn=self.connection_string)
except Error as e: # pass
self.error = str(e)[:250]
self.connector = None
return self
And the error only happens when execute
sql is executed. Is there any way to get a connection error at the moment of connection?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我添加了
execute('select 1')
。因为只有在执行后,我们才创建类的实例,因此在此之后,我才能获得连接异常。I added
execute('select 1')
. Because only after execute we are creating instance of class, so after that I can get connection exception.