diff options
author | Amjith Ramanujam <amjith.r@gmail.com> | 2015-01-06 21:21:41 -0800 |
---|---|---|
committer | Amjith Ramanujam <amjith.r@gmail.com> | 2015-01-06 21:21:41 -0800 |
commit | e4e9828640fc9046f65fb3791627a8ca91ad7e55 (patch) | |
tree | 86d36cfc7cd7241da8304e9350f3ed0e06de7cce | |
parent | 13b17b8141119d071e95a7918cc62bb1f2c0308b (diff) | |
parent | 4aaa117cddb61e20a40ea63adc7a61d4be4e8e39 (diff) |
Merge pull request #40 from macobo/master
Fix UnicodeDecodeError in python2
-rwxr-xr-x | pgcli/main.py | 6 | ||||
-rw-r--r-- | pgcli/pgexecute.py | 6 |
2 files changed, 10 insertions, 2 deletions
diff --git a/pgcli/main.py b/pgcli/main.py index 59be3ad0..b8f9cad8 100755 --- a/pgcli/main.py +++ b/pgcli/main.py @@ -3,6 +3,7 @@ from __future__ import unicode_literals from __future__ import print_function import os +import traceback import logging import click @@ -113,8 +114,9 @@ def cli(database, user, password, host, port): _logger.debug("status: %r", status) click.echo_via_pager('\n'.join(output)) except Exception as e: - _logger.debug("sql: %r, error: %r", document.text, e.message) - click.secho(e.message, err=True, fg='red') + _logger.error("sql: %r, error: %r", document.text, str(e)) + _logger.error("traceback: %r", traceback.format_exc()) + click.secho(str(e), err=True, fg='red') # Refresh the table names and column names if necessary. if need_completion_refresh(document.text): diff --git a/pgcli/pgexecute.py b/pgcli/pgexecute.py index e4eab6bf..2426882c 100644 --- a/pgcli/pgexecute.py +++ b/pgcli/pgexecute.py @@ -1,9 +1,15 @@ import logging import psycopg2 +import psycopg2.extensions from .packages import pgspecial _logger = logging.getLogger(__name__) +# Cast all database input to unicode automatically. +# See http://initd.org/psycopg/docs/usage.html#unicode-handling for more info. +psycopg2.extensions.register_type(psycopg2.extensions.UNICODE) +psycopg2.extensions.register_type(psycopg2.extensions.UNICODEARRAY) + def _parse_dsn(dsn, default_user, default_password, default_host, default_port): """ |