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

From: Karsten Hilbert <Karsten(dot)Hilbert(at)gmx(dot)net>
To: psycopg(at)postgresql(dot)org
Subject: Re: Using context managers for connections/cursors - cursors are closed, connections are not?
Date: 2013-11-27 11:19:55
Message-ID: 20131127111955.GL5031@hermes.hilbert.loc
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Browse psycopg by date

  From Date Subject
Next Message Daniele Varrazzo 2013-11-27 12:03:37 Re: Using context managers for connections/cursors - cursors are closed, connections are not?
Previous Message Victor Hooi 2013-11-27 00:24:34 Using context managers for connections/cursors - cursors are closed, connections are not?