summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>2016-12-29 22:36:04 +0100
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>2016-12-29 22:42:25 +0100
commit21f38a4c074d106c24e48e8e971d7215dace5911 (patch)
tree107418cafd23e2752b028cb5461e62c7cddc9fec
parent449bd4485f10bcf4dd557c62912623ec2774d86b (diff)
downloadpsycopg2-21f38a4c074d106c24e48e8e971d7215dace5911.tar.gz
Don't try to write bytes in the LoggingConnection file
Close #483
-rw-r--r--NEWS2
-rw-r--r--lib/extras.py2
2 files changed, 4 insertions, 0 deletions
diff --git a/NEWS b/NEWS
index ecde78d..b4d11e6 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 7fc853a..b59a2c7 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):