-1

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?

FeoJun
  • 103
  • 1
  • 14
  • I don't think this is possible, but you can add an issue to the clickhouse-driver project. You could also take a look at the alpha level clickhouse-connect driver officially supported by ClickHouse Inc – Geoff Genz Jun 08 '22 at 15:02

1 Answers1

0

I added execute('select 1'). Because only after execute we are creating instance of class, so after that I can get connection exception.

def __enter__(self):
    try:
        self.connector = dbp.connect(dsn=self.connection_string)
        self.cur = self.connector.cursor()
        self.cur.execute('select 1')
    except dbp.Error as e:
        self.error = '\nConnection error occurred: ' + '\n' + str(e)[:250]
        self.connector = None
    return self
FeoJun
  • 103
  • 1
  • 14