'SqlAlchemy equivalent of pyodbc connect string fails

The following works:

import pyodbc
import sqlalchemy as sa
import pandas as pd 

cnxn = pyodbc.connect('Driver=ODBC Driver 17 for SQL Server;Server=MyServer;Database=MyDB;Trusted_Connection=yes;')
sql = ("SELECT * FROM MyTable") 
data_df = pd.read_sql(sql,cnxn)  

The following do not work:

params = urllib.parse.quote_plus('Driver={ODBC Driver 17 for SQL Server};Server=MyServer;Database=MyDB;Trusted_Connection=yes;')
engine = sa.create_engine('mssql+pyodbc:///?odbc_connect=%s' % (params))
orgnummer_df = pd.read_sql_table("MyTable", engine)

Error message: Exception has occurred: ValueError Table MyTable not found

So I assume there is something wrong with my engine, but I am unable to figure it out... Can someone please point me in the right direction? Thanks!



Sources

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

Source: Stack Overflow

Solution Source