Differentiating various OperationalError 'states' - Mailing list psycopg

From Mario Splivalo
Subject Differentiating various OperationalError 'states'
Date
Msg-id 52F107B5.9040204@splivalo.hr
Whole thread Raw
Responses Re: Differentiating various OperationalError 'states'  (Daniele Varrazzo <daniele.varrazzo@gmail.com>)
List 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 by date:

Previous
From: Rich Harley
Date:
Subject: Re: bytea extraction
Next
From: Daniele Varrazzo
Date:
Subject: Re: Differentiating various OperationalError 'states'