Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/298.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/74.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python——列表索引超出范围——在一个简单的SELECT语句上?_Python_Sql - Fatal编程技术网

Python——列表索引超出范围——在一个简单的SELECT语句上?

Python——列表索引超出范围——在一个简单的SELECT语句上?,python,sql,Python,Sql,我是Python新手,所以可能我犯了一个新手错误。但在这种情况下,这似乎不是我应该犯的错误 在一个非常简单的SELECT语句中,我得到了一个列表索引超出范围的错误 sql = """ begin tran -- Several update statements are in this block. commit tran""" sql = sql.format(tablename=self.tablename, **self.map

我是Python新手,所以可能我犯了一个新手错误。但在这种情况下,这似乎不是我应该犯的错误

在一个非常简单的SELECT语句中,我得到了一个列表索引超出范围的错误

  sql = """
        begin tran
        -- Several update statements are in this block.

        commit tran"""
    sql = sql.format(tablename=self.tablename, **self.mappings)
    #print(sql)
    self.cursor.execute(sql, (self.catalog_id,self.catalog_id,self.catalog_id,))


    self.cursor.execute("SELECT CaptionText, DisplayOrder FROM dbo.SizeOrder where CaptionText is not NULL and len(CaptionText)>0")  #This is the line that breaks!

    size_order = {row[0].lower(): row[1] for row in self.cursor}
这是下一排倒数第二排。它没有做任何有趣的格式化。在这个问题查询中,我不做任何替换。直接对数据库运行时,它返回300多条记录

跟踪输出明确地暗示了这一行代码。我真的怀疑下一行b/c涉及索引。但执行死刑后的回归毫无帮助

    Traceback (most recent call last):
  File "import.py", line 782, in <module>
    main(sys.argv)
  File "import.py", line 167, in main
    db.transform_catalog((len(args)>4 and args[4] == "--skipimages") or (len(args)>5 and args[5] == "--skipimages") )
  File "import.py", line 235, in transform_catalog
    self.do_transform(skipImages)
  File "import.py", line 264, in do_transform
    self.insert_size_types()
  File "import.py", line 501, in insert_size_types
    self.cursor.execute("SELECT CaptionText, DisplayOrder FROM dbo.SizeOrder  where CaptionText is not NULL and len(Capt
ionText)>0")
  File "C:\Python33\lib\site-packages\pypyodbc.py", line 1449, in execute
    self._free_stmt(SQL_CLOSE)
  File "C:\Python33\lib\site-packages\pypyodbc.py", line 1971, in _free_stmt
    check_success(self, ret)
  File "C:\Python33\lib\site-packages\pypyodbc.py", line 986, in check_success
    ctrl_err(SQL_HANDLE_STMT, ODBC_obj.stmt_h, ret, ODBC_obj.ansi)
  File "C:\Python33\lib\site-packages\pypyodbc.py", line 951, in ctrl_err
    state = err_list[0][0]
IndexError: list index out of range

我可能做错了什么?谢谢

肯定是个bug。在库内部的某些结果处理过程中出现的不相关错误,与输入无关。是可能的原因。

这可能是一个长期的问题,但可能与PyODBC 1.3.3中修复的错误有关:您似乎忘记获取查询结果的结果=self.cursor.fetchallSo。。。解决办法是什么?是否有升级或service pack或修补程序??!还不够清楚吗?@ivan_pozdeev:它回到了1.3.4:索引器:列表索引出了range@user443854提出另一个问题,那肯定是另一回事。