'SQLAlchemy - Unable to reflect SQL view

I'm getting the following error message when trying to reflect any of my SQL views:

sqlalchemy/dialects/mysql/reflection.py", line 306, in _describe_to_create
    buffer.append(" ".join(line))
TypeError: sequence item 2: expected str instance, bytes found

I have tried using both the autoload_with and autoload=True options in my select query constructor to no avail.

I have the appropriate permissions on my view. My query is pretty simple:

company_country = Table('company_country', metadata, autoload_with=engine)
query = select(company_country.c.country)
return query

I've tried the inspect utility and it does not list my SQL view, nor does the reflecting all tables described below the views section on this page: https://docs.sqlalchemy.org/en/14/core/reflection.html#reflecting-views

I'm using version SQLAlchemy->1.4.32, Python 3.x and mySQL 8.0.28 on Mac if that's any help

I should add that I can query my SQL views using the text() constructor but it would be far more preferable to use select() if possible.

Any tips appreciated



Solution 1:[1]

I was using the mysql-connector client for interop with other code, but after switching to the mysqlclient, I was able to reflect the views.

https://docs.sqlalchemy.org/en/14/dialects/mysql.html#module-sqlalchemy.dialects.mysql.mysqldb

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 raven