Differentiating various OperationalError 'states'

Поиск
Список
Период
Сортировка
От Mario Splivalo
Тема Differentiating various OperationalError 'states'
Дата
Msg-id 52F107B5.9040204@splivalo.hr
обсуждение исходный текст
Ответы Re: Differentiating various OperationalError 'states'
Список psycopg
Hello.

I'd like to differentiate between:
- FATAL: no pg_hba.conf entry for host blah-blah
- could not connect to server: Connection Refused
- timeout expired


It seems that the only way to do so is to parse the string
OperationalError returns, something like this:

try:
  conn = psycopg2.connect(conn_string)
except psycopg2.OperationalError as err:
  if str(err).startswith('FATAL: no pg_hba'):
     # do stuff
  ...


Is there a better (more proper) way do figure out what went wrong when
OperationalException is thrown?

    Mario


В списке psycopg по дате отправления: