Differentiating various OperationalError 'states'

From: Mario Splivalo <mario(at)splivalo(dot)hr>
To: "psycopg(at)postgresql(dot)org" <psycopg(at)postgresql(dot)org>
Subject: Differentiating various OperationalError 'states'
Date: 2014-02-04 15:31:01
Message-ID: 52F107B5.9040204@splivalo.hr
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: 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

Responses

Browse psycopg by date

  From Date Subject
Next Message Daniele Varrazzo 2014-02-04 16:52:59 Re: Differentiating various OperationalError 'states'
Previous Message Rich Harley 2014-02-03 18:10:59 Re: bytea extraction