Home > Net >  AttributeError: 'NoneType' object has no attribute 'cursor' - Getting this error
AttributeError: 'NoneType' object has no attribute 'cursor' - Getting this error

Time:10-16

I have a flask-sqlalchemy query. I know that the below flask-sqlalchemy query code is valid because I am able to populate data on another page in an html table with the 'eintest' variable.

ticker = 'msft'
eintest = db.session.query(company).filter(company.instance==ticker)

All I am trying to do is convert that flask-sqlalchemy code above into a pandas data frame, as I am trying to do below.

df = pd.read_sql(eintest.statement, db.session.bind)

When I run my flask app, I get the error, "AttributeError: 'NoneType' object has no attribute 'cursor'". Does anyone know why this is? I've been trying many variations of that one line to read sql into a pandas dataframe but no luck yet.

CodePudding user response:

Arguments for pandas read_sql is a sql statement and a connection. You are passing a statement and a session. Here's what you'll need to change to get it to work:

# Load to a pandas dataframe
df = pd.read_sql(eintest.statement, db.get_engine())
  • Related