Re: Using context managers for connections/cursors - cursors are closed, connections are not? - Mailing list psycopg

From Karsten Hilbert
Subject Re: Using context managers for connections/cursors - cursors are closed, connections are not?
Date
Msg-id 20131127111955.GL5031@hermes.hilbert.loc
Whole thread Raw
In response to Using context managers for connections/cursors - cursors are closed, connections are not?  (Victor Hooi <victorhooi@yahoo.com>)
List psycopg
On Wed, Nov 27, 2013 at 11:24:34AM +1100, Victor Hooi wrote:

Quite apart from your question but if you do this:

> def get_pg_connection(logger_name, database_config):
...
>     except psycopg2.OperationalError as e:
>         logger.error('Error connecting to database {0[host]}:{0[port]}/{0[dbname]} - {1}'.format(database_config, e),
exc_info=True)
...
>     except Exception as e:
>         logger.error('Error - {}'.format(e), exc_info=True)

you will see UnicodeDecodeError from the logger
infrastructure as soon as the PostgreSQL error message
contains characters which don't fit the ASCII subset.
This will happen as soon as PostgreSQL is set to
a locale other then C or en_*

Karsten
--
GPG key ID E4071346 @ gpg-keyserver.de
E167 67FD A291 2BEA 73BD  4537 78B9 A9F9 E407 1346


psycopg by date:

Previous
From: Victor Hooi
Date:
Subject: Using context managers for connections/cursors - cursors are closed, connections are not?
Next
From: Daniele Varrazzo
Date:
Subject: Re: Using context managers for connections/cursors - cursors are closed, connections are not?