postgresql - get psycopg2 errors in python3 -


i've psycopg2 version 2.6.1 want fetch errors, dont work excpected:

try:     pgconn = psycopg2.connect(database="foobar", host="dbtest.example.de", user="postgresss") except psycopg2.operationalerror:     print(psycopg2.operationalerror.pgerror)    .....:      <member 'pgerror' of 'psycopg2.error' objects> 

or:

try:                            pgconn = psycopg2.connect(database="foobar", host="dbtest.example.de", user="postgresss") except psycopg2.operationalerror:     print(psycopg2.operationalerror.diag)    .....:      <attribute 'diag' of 'psycopg2.error' objects> 

how can see correct message "no pg_hba.conf entry host xyz"

you need reference exception instance:

try:     pgconn = psycopg2.connect(database="foobar", host="dbtest.example.de", user="postgresss") except psycopg2.operationalerror e:     print(e) 

Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -