NoneType object is not iterable error in pandas

后端 未结 3 685
粉色の甜心
粉色の甜心 2020-12-18 03:07

I am trying to pull some data from a stored proc on a sql server using python.

Here is my code:

import datetime as dt
import pyodbc
import pandas as          


        
相关标签:
3条回答
  • 2020-12-18 03:45

    Your sproc needs

    SET NOCOUNT ON;
    

    Without this sql will return the rowcount for the call, which will come back without a column name, causing the NoneType error.

    0 讨论(0)
  • 2020-12-18 03:55

    pd.read_sql() expects to have output to return, and tries to iterate through the output; that's where the TypeError is coming from. Instead, execute with a cursor object:

    import datetime as dt
    import pyodbc
    import pandas as pd
    
    conn = pyodbc.connect('Trusted_Connection=yes', driver = '{SQL Server Native client 11.0}',server = '*****', database = '**')
    cur = conn.cursor()
    cur.execute("EXEC ******** '20140528'")
    

    You won't receive any output, but since none is expected, your code should run without error.

    0 讨论(0)
  • 2020-12-18 04:05
    import datetime as dt
    import pyodbc
    import pandas as pd
    
    conn = pyodbc.connect('Trusted_Connection=yes; driver =SQL Server Native client 
    11.0; server = *****, database = **')
    sqlSend = conn.cursor()
    sqlSend.execute(f"EXEC ******** '20140528'")
    conn.commint()
    
    0 讨论(0)
提交回复
热议问题