Skip to content

Error opening sqlalchemy connection using latest version (2.0.908) #116

Description

@CarlosAdp

Driver version

2.0.908

Redshift version

PostgreSQL 8.0.2 on i686-pc-linux-gnu, compiled by GCC gcc (GCC) 3.4.2 20041017 (Red Hat 3.4.2-6.fc3), Redshift 1.0.38698

Client Operating System

Windows 11 Pro, Version 21H2, OS Build 22000.739

Python version

Python 3.8.10

Table schema

Not necessary

Problem description

  1. Expected behaviour:
    The following sequence of Python statements should open a connection with no errors:
import sqlalchemy

CONN_STR = f'redshift+redshift_connector://{user}:{password}@{host}:{port}/{db}'
engine = sqlalchemy.create_engine(CONN_STR)
connection = engine.connect()
  1. Actual behaviour:
    It throwed the Exception stack below.

  2. Error message/stack trace:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<VENV_FOLDER>\lib\site-packages\sqlalchemy\engine\base.py", line 3234, in connect
    return self._connection_cls(self, close_with_result=close_with_result)
  File "<VENV_FOLDER>\lib\site-packages\sqlalchemy\engine\base.py", line 96, in __init__
    else engine.raw_connection()
  File "<VENV_FOLDER>\lib\site-packages\sqlalchemy\engine\base.py", line 3313, in raw_connection
    return self._wrap_pool_connect(self.pool.connect, _connection)
  File "<VENV_FOLDER>\lib\site-packages\sqlalchemy\engine\base.py", line 3280, in _wrap_pool_connect
    return fn()
  File "<VENV_FOLDER>\lib\site-packages\sqlalchemy\pool\base.py", line 310, in connect
    return _ConnectionFairy._checkout(self)
  File "<VENV_FOLDER>\lib\site-packages\sqlalchemy\pool\base.py", line 868, in _checkout
    fairy = _ConnectionRecord.checkout(pool)
  File "<VENV_FOLDER>\lib\site-packages\sqlalchemy\pool\base.py", line 476, in checkout
    rec = pool._do_get()
  File "<VENV_FOLDER>\lib\site-packages\sqlalchemy\pool\impl.py", line 146, in _do_get
    self._dec_overflow()
  File "<VENV_FOLDER>\lib\site-packages\sqlalchemy\util\langhelpers.py", line 70, in __exit__
    compat.raise_(
  File "<VENV_FOLDER>\lib\site-packages\sqlalchemy\util\compat.py", line 208, in raise_
    raise exception
  File "<VENV_FOLDER>\lib\site-packages\sqlalchemy\pool\impl.py", line 143, in _do_get
    return self._create_connection()
  File "<VENV_FOLDER>\lib\site-packages\sqlalchemy\pool\base.py", line 256, in _create_connection
    return _ConnectionRecord(self)
  File "<VENV_FOLDER>\lib\site-packages\sqlalchemy\pool\base.py", line 371, in __init__
    self.__connect()
  File "<VENV_FOLDER>\lib\site-packages\sqlalchemy\pool\base.py", line 677, in __connect
    pool.dispatch.connect.for_modify(
  File "<VENV_FOLDER>\lib\site-packages\sqlalchemy\event\attr.py", line 329, in _exec_w_sync_on_first_run
    self(*args, **kw)
  File "<VENV_FOLDER>\lib\site-packages\sqlalchemy\event\attr.py", line 343, in __call__
    fn(*args, **kw)
  File "<VENV_FOLDER>\lib\site-packages\sqlalchemy\util\langhelpers.py", line 1695, in go
    return once_fn(*arg, **kw)
  File "<VENV_FOLDER>\lib\site-packages\sqlalchemy\engine\create.py", line 686, in first_connect
    dialect.initialize(c)
  File "<VENV_FOLDER>\lib\site-packages\sqlalchemy\dialects\postgresql\base.py", line 3344, in initialize
    super(PGDialect, self).initialize(connection)
  File "<VENV_FOLDER>\lib\site-packages\sqlalchemy\engine\default.py", line 407, in initialize
    self.server_version_info = self._get_server_version_info(
  File "<VENV_FOLDER>\lib\site-packages\sqlalchemy\dialects\postgresql\base.py", line 3590, in _get_server_version_info
    v = connection.exec_driver_sql("select pg_catalog.version()").scalar()
  File "<VENV_FOLDER>\lib\site-packages\sqlalchemy\engine\base.py", line 1686, in exec_driver_sql
    return self._exec_driver_sql(
  File "<VENV_FOLDER>\lib\site-packages\sqlalchemy\engine\base.py", line 1595, in _exec_driver_sql
    ret = self._execute_context(
  File "<VENV_FOLDER>\lib\site-packages\sqlalchemy\engine\base.py", line 1862, in _execute_context
    self._handle_dbapi_exception(
  File "<VENV_FOLDER>\lib\site-packages\sqlalchemy\engine\base.py", line 2047, in _handle_dbapi_exception
    util.raise_(exc_info[1], with_traceback=exc_info[2])
  File "<VENV_FOLDER>\lib\site-packages\sqlalchemy\util\compat.py", line 208, in raise_
    raise exception
  File "<VENV_FOLDER>\lib\site-packages\sqlalchemy\engine\base.py", line 1835, in _execute_context
    result = context._setup_result_proxy()
  File "<VENV_FOLDER>\lib\site-packages\sqlalchemy\engine\default.py", line 1449, in _setup_result_proxy
    result = self._setup_dml_or_text_result()
  File "<VENV_FOLDER>\lib\site-packages\sqlalchemy\engine\default.py", line 1539, in _setup_dml_or_text_result
    result = _cursor.LegacyCursorResult(
  File "<VENV_FOLDER>\lib\site-packages\sqlalchemy\engine\cursor.py", line 1264, in __init__
    metadata = self._init_metadata(context, cursor_description)
  File "<VENV_FOLDER>\lib\site-packages\sqlalchemy\engine\cursor.py", line 1326, in _init_metadata
    self._metadata = metadata = self._cursor_metadata(
  File "<VENV_FOLDER>\lib\site-packages\sqlalchemy\engine\cursor.py", line 180, in __init__
    raw = self._merge_cursor_description(
  File "<VENV_FOLDER>\lib\site-packages\sqlalchemy\engine\cursor.py", line 415, in _merge_cursor_description
    return [
  File "<VENV_FOLDER>\lib\site-packages\sqlalchemy\engine\cursor.py", line 415, in <listcomp>
    return [
  File "<VENV_FOLDER>\lib\site-packages\sqlalchemy\engine\cursor.py", line 596, in _merge_cols_by_none
    for (
  File "<VENV_FOLDER>\lib\site-packages\sqlalchemy\engine\cursor.py", line 466, in _colnames_from_description
    colname = description_decoder(colname)
TypeError: expected bytes, str found

expected bytes, str found
  1. Any other details that can be helpful:
    Downgrading redshift-connector version to 2.0.907 solved the issue:
pip install redshift-connector==2.0.907

Python Driver trace logs

Not sure what this means.

Reproduction code

import sqlalchemy

CONN_STR = f'redshift+redshift_connector://{user}:{password}@{host}:{port}/{db}'
engine = sqlalchemy.create_engine(CONN_STR)
connection = engine.connect()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions