I am having trouble using ConfigParser()
and an ini
file with pandas
.
I get this error:
UserWarning: pandas only support SQLAlchemy connectable(engine/connection) ordatabase string URI or sqlite3 DBAPI2 connectionother DBAPI2 objects are not tested, please consider using SQLAlchemy
I have this defined in my ini
file:
[options]
myQuery = SELECT TOP (1000) * FROM [Books].[dbo].[springBooks]
In my Python script, I assign it the dbQuery
variable like this:
dbQuery = config['options']['myQuery']
And I use it like this:
mydb = pyodbc.connect(Driver=driver,
Server=server,
Database=db,
uid=user, pwd=pw)
print(dbQuery)
df = pd.read_sql_query(
dbQuery, mydb)
When I print the query out, it looks fine like this:
SELECT TOP (1000) * FROM [Books].[dbo].[springBooks]
If I hard-code the query into the statement it works fine:
df = pd.read_sql_query(
'''SELECT TOP (1000) * FROM [Books].[dbo].[springBooks]''', mydb)
What could I be messing up so bad?
Thanks!