IBM/sqlalchemy-ibmi

TypeError: expected bytes, str found

qtemp opened this issue · 3 comments

qtemp commented

I'm trying to replicate the readme example; though with my connection info, different table, different schema.

It's failing on:

table = sa.Table('eventlog', metadata, autoload=True, autoload_with=engine, schema=DEFAULT_SCHEMA)

Any ideas?

(base) C:\Users\S111059\Desktop\Python\in2>python app.py
Traceback (most recent call last):
  File "app.py", line 18, in <module>
    table = sa.Table('eventlog', metadata, autoload=True, autoload_with=engine, schema=DEFAULT_SCHEMA)
  File "<string>", line 2, in __new__
  File "C:\Users\S111059\Anaconda3\lib\site-packages\sqlalchemy\util\deprecations.py", line 298, in warned
    return fn(*args, **kwargs)
  File "C:\Users\S111059\Anaconda3\lib\site-packages\sqlalchemy\sql\schema.py", line 601, in __new__
    metadata._remove_table(name, schema)
  File "C:\Users\S111059\Anaconda3\lib\site-packages\sqlalchemy\util\langhelpers.py", line 70, in __exit__
    compat.raise_(
  File "C:\Users\S111059\Anaconda3\lib\site-packages\sqlalchemy\util\compat.py", line 207, in raise_
    raise exception
  File "C:\Users\S111059\Anaconda3\lib\site-packages\sqlalchemy\sql\schema.py", line 596, in __new__
    table._init(name, metadata, *args, **kw)
  File "C:\Users\S111059\Anaconda3\lib\site-packages\sqlalchemy\sql\schema.py", line 671, in _init
    self._autoload(
  File "C:\Users\S111059\Anaconda3\lib\site-packages\sqlalchemy\sql\schema.py", line 706, in _autoload
    conn_insp.reflect_table(
  File "C:\Users\S111059\Anaconda3\lib\site-packages\sqlalchemy\engine\reflection.py", line 774, in reflect_table
    for col_d in self.get_columns(
  File "C:\Users\S111059\Anaconda3\lib\site-packages\sqlalchemy\engine\reflection.py", line 497, in get_columns
    col_defs = self.dialect.get_columns(
  File "<string>", line 2, in get_columns
  File "C:\Users\S111059\Anaconda3\lib\site-packages\sqlalchemy\engine\reflection.py", line 55, in cache
    ret = fn(self, con, *args, **kw)
  File "C:\Users\S111059\Anaconda3\lib\site-packages\sqlalchemy_ibmi\base.py", line 1073, in get_columns
    for row in connection.execute(query):
  File "C:\Users\S111059\Anaconda3\lib\site-packages\sqlalchemy\engine\result.py", line 382, in iterrows
    row = make_row(row) if make_row else row
TypeError: expected bytes, str found
qtemp commented

Added echo=True to the create_engine statement.

This produces the following, prior to the traceback mentioned above.

2021-09-17 16:34:47,330 INFO sqlalchemy.engine.Engine VALUES CURRENT_SCHEMA
2021-09-17 16:34:47,330 INFO sqlalchemy.engine.Engine [raw sql] ()
2021-09-17 16:34:47,375 INFO sqlalchemy.engine.Engine SELECT COUNT(*) FROM QSYS2.SYSTEXTSERVERS
2021-09-17 16:34:47,376 INFO sqlalchemy.engine.Engine [raw sql] ()
2021-09-17 16:34:47,647 INFO sqlalchemy.engine.Engine SELECT "QSYS2"."SYSCOLUMNS"."COLUMN_NAME", "QSYS2"."SYSCOLUMNS"."DATA_TYPE", "QSYS2"."SYSCOLUMNS"."COLUMN_DEFAULT", "QSYS2"."SYSCOLUMNS"."IS_NULLABLE", "QSYS2"."SYSCOLUMNS"."LENGTH", "QSYS2"."SYSCOLUMNS"."NUMERIC_SCALE", "QSYS2"."SYSCOLUMNS"."IS_IDENTITY", "QSYS2"."SYSCOLUMNS"."IDENTITY_GENERATION"
FROM "QSYS2"."SYSCOLUMNS"
WHERE "QSYS2"."SYSCOLUMNS"."TABLE_SCHEMA" = ? AND "QSYS2"."SYSCOLUMNS"."TABLE_NAME" = ? ORDER BY "QSYS2"."SYSCOLUMNS"."ORDINAL_POSITION"
2021-09-17 16:34:47,651 INFO sqlalchemy.engine.Engine [dialect sqlalchemy_ibmi+pyodbc does not support caching 0.00119s] ('GALLMANM', 'EVENTLOG')

I too was getting: TypeError: expected bytes, str found while using SQLAclchemy 1.4

I downgraded my environment to SQLAlchemy ~1.3

I can confirm it does not generate an error with ~1.3

with SQLAlchemy 1.4 i observed that all records were created even though it resulted in an error

Duplicate of #133