python - SQLAlchemy - 'engine' object has no attribute 'cursor' - Stack Overflow

admin2025-04-15  3

I was working on this code for the last few months and never had issues with sqlalchemy and connection to my ms sql database. However, yesterday I installed dataset, tokenizer, sklearn and joblib, and now my database connection is not working.

This is my connection part of the code that worked without issues before:

connection_string = (
    'mssql+pyodbc:///?odbc_connect='
    f'DRIVER={{ODBC Driver 18 for SQL Server}};'
    f'SERVER={server};'
    f'DATABASE={database};'
    'Trusted_Connection=yes;'
    'TrustServerCertificate=yes;'
)

engine = create_engine(connection_string)

df = pd.read_sql('table', engine)

Now I have error message: 'Engine' object has no attribute 'cursor'

I have tried changing versions of sqlalchemy, pyodbc, but still the same error occurs. I also tried - read_sql_table, read_sql_query.

Thank you for your help!

UPDATE I managed to fix this by deleting all python libraries and installing them all over again, however I would still appreciate a solution for this problem.

转载请注明原文地址:http://www.anycun.com/QandA/1744731923a86836.html