From: | "Karsten Hilbert" <Karsten(dot)Hilbert(at)gmx(dot)net> |
---|---|
To: | |
Cc: | psycopg(at)postgresql(dot)org |
Subject: | Re: psycopg2: distinguishing connect failures through exception handling |
Date: | 2017-08-02 05:25:55 |
Message-ID: | trinity-add0f822-577b-4923-8079-9bf6482faa08-1501651555817@3capp-gmx-bs61 |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | psycopg |
<html><head></head><body><div style="font-family: Verdana;font-size: 12.0px;"><div>
<div>You probably want to look at pgping.</div>
<div> </div>
<div>Karsten</div>
<div>
<div name="quote" style="margin:10px 5px 5px 10px; padding: 10px 0 10px 10px; border-left:2px solid #C3D9E5; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;">
<div style="margin:0 0 10px 0;"><b>Gesendet:</b> Mittwoch, 02. August 2017 um 06:20 Uhr<br/>
<b>Von:</b> "Stephen Quintero" <30blows(at)gmail(dot)com><br/>
<b>An:</b> psycopg(at)postgresql(dot)org<br/>
<b>Betreff:</b> [psycopg] psycopg2: distinguishing connect failures through exception handling</div>
<div name="quoted-content">
<div>Hi Folks,
<div> </div>
<div>My first email here. I am using psycopg2 to remotely verify a postgres server is up, and separately that it is accessible given a particular user/password/database. This is done using <font face="monospace, monospace">psycopg2.connect(args...)</font>. The use case is automated deployment of the docker postgres container, where I wish to distinguish postgres service is up from postgres service cannot be accessed (e.g., with your user/password/database), from postgres service is down, in order to verify the container deployment.</div>
<div> </div>
<div>It seems the <font face="monospace, monospace">psycopg2.OperationalError</font> exception is thrown in a variety of circumstances: database does not exist, authentication failed, no password supplied, etc. But, the exception pgcode and pgerror are not set, evidently unless there is a successful connect. This leaves me in the position of distinguishing failures based on the error message string, e.g. <font color="#073763" face="monospace, monospace">fe_sendauth: no password supplied</font> or <font color="#073763" face="monospace, monospace">FATAL: password authentication failed for user "<val>"</font></div>
<div> </div>
<div>This does not seem like a reliable method, one certain to work in the future, and known to work now across myriad versions of postgres (outside the scope of my practical testing).</div>
<div> </div>
<div>I have these two questions. Is this understanding correct? Is there a reliable means to distinguish the types of connect failures using psycopg2?</div>
<div> </div>
<div>Thank you for your time.</div>
<div> </div>
<div>Best regards,</div>
<div> </div>
<div>Stephen Quintero</div>
<div> </div>
</div>
</div>
</div>
</div>
</div></div></body></html>
Attachment | Content-Type | Size |
---|---|---|
unknown_filename | text/html | 2.6 KB |
From | Date | Subject | |
---|---|---|---|
Next Message | Daniele Varrazzo | 2017-08-02 14:10:15 | Re: Changing set_session implementation |
Previous Message | Stephen Quintero | 2017-08-02 04:20:44 | psycopg2: distinguishing connect failures through exception handling |