'NoneType'对象在python3中不可迭代

时间:2018-06-05 22:39:20

标签: python python-3.x pandas

我正在尝试执行不带参数的存储过程并将输出插入到excel中。

在SSMS中,此存储过程运行正常。

但在这里它重新出现错误'NoneType' object is not iterable

有趣的事情很简单SELECT声明工作正常。但存储过程给我带来了麻烦。

import pandas as pd
import pyodbc
 #parameters:
server = 'MyServer'
db = 'MyDB'
conn = pyodbc.connect('DRIVER={SQL Server};server='+server+';DATABASE='+ db+';Trusted_Connection=yes;')
sql = """
        execute Align_rsUnitedSpecPolicyDataFeed
"""
df = pd.read_sql(sql,conn)
df.to_excel(r"C:\UserName\DestinationFolder\Test.xlsx") 

这是我得到的错误:

  TypeError                                 Traceback (most recent call last)
    <ipython-input-31-d769e9510d21> in <module>()
         15         execute Align_rsUnitedSpecPolicyDataFeed
         16 """
    ---> 17 df = pd.read_sql(sql,conn)
         18 df.shape
         19 #df.to_excel(r"C:\Users\Username\Test.xlsx")

    C:\Users\oserdyuk\AppData\Local\Continuum\Anaconda3\lib\site-packages\pandas\io\sql.py in read_sql(sql, con, index_col, coerce_float, params, parse_dates, columns, chunksize)
        397             sql, index_col=index_col, params=params,
        398             coerce_float=coerce_float, parse_dates=parse_dates,
    --> 399             chunksize=chunksize)
        400 
        401     try:

    C:\Users\Username\AppData\Local\Continuum\Anaconda3\lib\site-packages\pandas\io\sql.py in read_query(self, sql, index_col, coerce_float, params, parse_dates, chunksize)
       1435         args = _convert_params(sql, params)
       1436         cursor = self.execute(*args)
    -> 1437         columns = [col_desc[0] for col_desc in cursor.description]
       1438 
       1439         if chunksize is not None:

    TypeError: 'NoneType' object is not iterable

0 个答案:

没有答案