From 21f38a4c074d106c24e48e8e971d7215dace5911 Mon Sep 17 00:00:00 2001 From: Daniele Varrazzo Date: Thu, 29 Dec 2016 22:36:04 +0100 Subject: [PATCH] Don't try to write bytes in the LoggingConnection file Close #483 --- NEWS | 2 ++ lib/extras.py | 2 ++ 2 files changed, 4 insertions(+) diff --git a/NEWS b/NEWS index ecde78d3..b4d11e64 100644 --- a/NEWS +++ b/NEWS @@ -27,6 +27,8 @@ New features: - `~cursor.callproc()` now accepts a dictionary of parameters (:ticket:`#381`). - Using Python C API decoding functions and codecs caching for faster unicode encoding/decoding (:ticket:`#473`). +- Fixed error caused by missing decoding `~psycopg2.extras.LoggingConnection` + (:ticket:`#483`). Other changes: diff --git a/lib/extras.py b/lib/extras.py index 7fc853a6..b59a2c76 100644 --- a/lib/extras.py +++ b/lib/extras.py @@ -395,6 +395,8 @@ class LoggingConnection(_connection): def _logtofile(self, msg, curs): msg = self.filter(msg, curs) if msg: + if _sys.version_info[0] >= 3 and isinstance(msg, bytes): + msg = msg.decode(_ext.encodings[self.encoding], 'replace') self._logobj.write(msg + _os.linesep) def _logtologger(self, msg, curs):