How to catch exception clickhouse_driver dbapi?

719 Views Asked by At

I want to catch exception while executing scipts/connecting to base using clickhouse_driver-drive dbapi.

Can I catch errors codes and errors message like

errorcodes.lookup(e.pgcode) 

and

e.diag.message_primary

from psycopg2.import errorcodes?

1

There are 1 best solutions below

0
On

Assuming you're using the most well known clickhouse-driver from here: https://pypi.org/project/clickhouse-driver (GitHub here: https://github.com/mymarilyn/clickhouse-driver), you must catch standard exceptions/errors. Most errors are defined in the clickhouse_driver.connection module, and they include socket errors, EOF errors, and other lower level errors.

Even though the dbapi for that project defines exception classes, none of them are actually used in the code. The driver does not in any way use the errors or error codes from the PostgreSQL psycopg2 project.