0
请原谅我,我是相当新的python,我一直在寻找这段的逻辑很长一段时间,但是,不管我尝试什么,看起来它总是在打印语句中崩溃。基本上,我只想知道python是否从SQL语句中获得了正确的值。我甚至试图做一个 a,b,c = row.split(',')
然后print a
,但它也出现在打印错误。获取“命令不同步,你现在不能运行这个命令”
with con:
cur.execute(query, (next, end,next,end))
print (cur._last_executed) # this prints the correct query.
while True:
result = cur.fetchmany()
if len(result) ==0:
break
for row in result:
myvalues = row.split(',')
for value in myvalues:
print value # this line is what the traceback says caused it.
错误输出:
Traceback (most recent call last):
File "./export.py", line 55, in <module>
print value
File "/usr/local/lib/python2.7/dist-packages/MySQL_python-1.2.3-py2.7-linux-x86_64.egg/MySQLdb/connections.py", line 249, in __exit__
self.rollback()
_mysql_exceptions.ProgrammingError: (2014, "Commands out of sync; you can't run this command now")
Exception _mysql_exceptions.ProgrammingError: (2014, "Commands out of sync; you can't run this command now") in <bound method SSCursor.__del__ of <MySQLdb.cursors.SSCursor object at 0x7fc0e0632f10>> ignored
我猜'row'不是一个字符串,所以'row.split'看起来不对...... – 2014-11-03 19:11:33
回溯清楚地表明,当你调用'self.rollback()',甚至没有出现错误时在你提供的代码中。而且,如果你没有显示你正在运行的命令,你如何期望我们调试你的命令不同步的方式? – 2014-11-03 19:11:41
请显示完整的回溯 - 从您提供的错误信息看,它看起来不像'print value'行是什么引起了异常。 – martineau 2014-11-03 19:14:29