I created a database connection and it works. But when I try to load the tables I get an error. What am I doing wrong? And i try metadata = MetaData(engine) but is the same error. I tried to change the sqlalchemy version but that didn't help either.
import urllib
from sqlalchemy import create_engine, MetaData, Table
import security
engine = create_engine('postgresql+psycopg2://example:%s@example/example' % (
urllib.parse.quote_plus(security.example_password),), echo=False)
metadata = MetaData(engine, schema='public')
print(engine.table_names())
invoices = Table('invoices', metadata, autoload=True)
print(repr(invoices))
Error is: Traceback (most recent call last):
File "C:\Users\dgebk\PycharmProjects\sql\main.py", line 14, in <module>
invoices = Table('invoices', metadata, autoload=True)
File "<string>", line 2, in __new__
File "C:\Users\dgebk\AppData\Local\Programs\Python\Python39\lib\site-packages\sqlalchemy\util\deprecations.py", line 298, in warned
return fn(*args, **kwargs)
File "C:\Users\dgebk\AppData\Local\Programs\Python\Python39\lib\site-packages\sqlalchemy\sql\schema.py", line 601, in __new__
metadata._remove_table(name, schema)
File "C:\Users\dgebk\AppData\Local\Programs\Python\Python39\lib\site-packages\sqlalchemy\util\langhelpers.py", line 70, in __exit__
compat.raise_(
File "C:\Users\dgebk\AppData\Local\Programs\Python\Python39\lib\site-packages\sqlalchemy\util\compat.py", line 207, in raise_
raise exception
File "C:\Users\dgebk\AppData\Local\Programs\Python\Python39\lib\site-packages\sqlalchemy\sql\schema.py", line 596, in __new__
table._init(name, metadata, *args, **kw)
File "C:\Users\dgebk\AppData\Local\Programs\Python\Python39\lib\site-packages\sqlalchemy\sql\schema.py", line 671, in _init
self._autoload(
File "C:\Users\dgebk\AppData\Local\Programs\Python\Python39\lib\site-packages\sqlalchemy\sql\schema.py", line 706, in _autoload
conn_insp.reflect_table(
File "C:\Users\dgebk\AppData\Local\Programs\Python\Python39\lib\site-packages\sqlalchemy\engine\reflection.py", line 774, in reflect_table
for col_d in self.get_columns(
File "C:\Users\dgebk\AppData\Local\Programs\Python\Python39\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\dgebk\AppData\Local\Programs\Python\Python39\lib\site-packages\sqlalchemy\engine\reflection.py", line 55, in cache
ret = fn(self, con, *args, **kw)
File "C:\Users\dgebk\AppData\Local\Programs\Python\Python39\lib\site-packages\sqlalchemy\dialects\postgresql\base.py", line 3663, in get_columns
for rec in self._load_enums(connection, schema="*")
File "C:\Users\dgebk\AppData\Local\Programs\Python\Python39\lib\site-packages\sqlalchemy\dialects\postgresql\base.py", line 4392, in _load_enums
for enum in c.fetchall():
File "C:\Users\dgebk\AppData\Local\Programs\Python\Python39\lib\site-packages\sqlalchemy\engine\result.py", line 983, in fetchall
return self._allrows()
File "C:\Users\dgebk\AppData\Local\Programs\Python\Python39\lib\site-packages\sqlalchemy\engine\result.py", line 400, in _allrows
rows = self._fetchall_impl()
File "C:\Users\dgebk\AppData\Local\Programs\Python\Python39\lib\site-packages\sqlalchemy\engine\cursor.py", line 1791, in _fetchall_impl
return self.cursor_strategy.fetchall(self, self.cursor)
File "C:\Users\dgebk\AppData\Local\Programs\Python\Python39\lib\site-packages\sqlalchemy\engine\cursor.py", line 975, in fetchall
self.handle_exception(result, dbapi_cursor, e)
File "C:\Users\dgebk\AppData\Local\Programs\Python\Python39\lib\site-packages\sqlalchemy\engine\cursor.py", line 935, in handle_exception
result.connection._handle_dbapi_exception(
File "C:\Users\dgebk\AppData\Local\Programs\Python\Python39\lib\site-packages\sqlalchemy\engine\base.py", line 1998, in _handle_dbapi_exception
util.raise_(exc_info[1], with_traceback=exc_info[2])
File "C:\Users\dgebk\AppData\Local\Programs\Python\Python39\lib\site-packages\sqlalchemy\util\compat.py", line 207, in raise_
raise exception
File "C:\Users\dgebk\AppData\Local\Programs\Python\Python39\lib\site-packages\sqlalchemy\engine\cursor.py", line 971, in fetchall
rows = dbapi_cursor.fetchall()
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc5 in position 1: ordinal not in range(128)
Process finished with exit code 1