Python 无法从最终异常模块调用函数

Python 无法从最终异常模块调用函数,python,multithreading,function,download,Python,Multithreading,Function,Download,我想从finally错误检测模块调用一个函数,并传递一个变量。但它显示的错误如下: TypeError:'NoneType'对象没有属性'\uuu getitem\uuu' 我的代码如下: from mysql.connector import MySQLConnection, Error import MySQLdb import sys import time import signal #from python_mysql_dbconfig import read_db_config #

我想从finally错误检测模块调用一个函数,并传递一个变量。但它显示的错误如下:

TypeError:'NoneType'对象没有属性'\uuu getitem\uuu'
我的代码如下:

from mysql.connector import MySQLConnection, Error
import MySQLdb
import sys
import time
import signal
#from python_mysql_dbconfig import read_db_config
#from MySQL import row

sys.setrecursionlimit(1500)

def query_with_fetchone():
    try:
        db = MySQLdb.connect(host="localhost",  # your host, usually localhost
                             user="root",  # your username
                             passwd="faheemmcfc",  # your password
                             db="python")  # name of the data base
        cur=db.cursor()
        cursor = db.cursor()
        cursor.execute("SELECT * FROM down")
        queue=0
        data= cursor.fetchone()
        lastid=data[0]
        print(data[0])
        def check(lastid):
            print lastid
            global last
            last=lastid
            while True:
                cursor.execute("Select * from down where id>%s"%(last))
                data = cursor.fetchone()
                last=data[0]
                print(data[0])
                print data[1]
                #signal.pause()
        check(lastid)
    except Error as e:
        print(e)
    finally:
        print'last',last
        time.sleep(30)
        check(last)
if __name__ == '__main__':
    query_with_fetchone()
在这里,我需要无限地运行while循环,以便在数据库中创建新条目时可以检索它。 当我从finally调用check时,它显示错误为:

/usr/bin/python2.7/home/faheem/pycharm项目/untitled1/test2.py 1
2中央除尘器3风机控制4中央除尘器5风机控制6中央除尘器最后6
回溯(最近一次调用上次):文件
“/home/faheem/PycharmProjects/untitled1/test2.py”,第55行,in
使用_fetchone()文件“/home/faheem/PycharmProjects/untitled1/test2.py”查询_,第45行,在
使用\u fetchone查询\u
检查(最后一个)文件“/home/faheem/PycharmProjects/untitled1/test2.py”,检查中的第34行
last=数据[0]类型错误:“非类型”对象没有属性“\uuuu getitem\uuuu”
进程已完成,退出代码为1
请告诉我如何更正它,或者提供另一种方法来无限地运行while循环,而不允许它转到finally部分。
请随意更正这个问题,因为我对stackoverflow不太熟悉。

提示:您收到一个错误,因为“数据”是无的。什么情况下cursor.fetchone()返回无?好吧,您的查询可能没有返回。。这就是为什么不能执行数据[0]
fetchone()
如果没有更多行可用,则返回None。如果数据为无,则应测试
等。如果实时添加更多行,则会显示相同的错误。。我希望我们循环无限次地运行,检查数据库中的新条目。。。请给我一个解决方案@cdarke