【发布时间】:2015-11-12 12:45:53
【问题描述】:
我试图在数据库中使用 cursor.execute 更新记录,但它总是返回 NoneType not iterable 错误,所以我决定使用类似“select curtime()”之类的简单方法进行测试,它给出了相同的错误。
cnx=pymysql.connect(user=user,password=pw,
host=127.0.0.1,port=3306,db=test,autocommit=True)
cursor=cnx.cursor()
cursor.execute('Select curtime()')
我得到'TypeError:'NoneType'对象不可迭代'
编辑: 我明白你需要完整的回溯是什么意思,我回到家,问题就消失了
File "/opt/anaconda3/lib/python3.4/site-packages/pymysql/cursors.py", line 51, in close
while self.nextset():
我从其他文章中发现了这个错误,因为我之前的真实 sql 语句字符串 cursor.execute(longsqlstatement) 很长,当我尝试关闭连接和游标时,它会导致该错误.在我的 curtime() 测试中,因为我之前的游标还没有完成执行它也会导致 NoneType 错误。所以我的问题是我怎么知道所有的 sql 语句已经成功运行并且我可以关闭连接?
【问题讨论】:
-
不是来自你没有的代码。请显示完整的回溯。