在我的raspberry pi上运行python/mysqldb时遇到了一些问题。这是一个相当简单的脚本,所以我不确定我遗漏了什么。“SELECT*FROM…”运行起来没有问题,但我似乎无法用新值更新表。脚本运行时不会引发错误,但当我使用ctrl-C时,它会显示以下内容:
Exception _mysql_exceptions.ProgrammingError: (2014, "Commands out of sync; you can't run this command now") in bound method DictCursor.__del of MySQLdb.cursors.DictCursor object at 0x19dfd90
这是我的剧本:
dhost = "localhost"
duser = "root"
dname = "rpi"
dpass = "datPassword"
import MySQLdb
try:
con = MySQLdb.connect(dhost,duser,dpass,dname);
cur = con.cursor(MySQLdb.cursors.DictCursor)
except MySQLdb.Error, e:
print "Error %d: %s" % (e.args[0],e.args[1])
sys.exit(1)
def websiteToSensor():
cur.execute("SELECT * FROM homeauto WHERE changedby = 'website'")
rows = cur.fetchall()
for row in rows:
cur.execute("UPDATE homeauto SET changedby = 'script' WHERE id = '%s'",(row["id"]))
return
while True:
websiteToSensor()
有人知道为什么我的表没有更新吗?谢谢!在
编辑:解决方案
多亏了Martijn Pieters,我的新websiteToSensor()代码如下:
^{pr2}$
尝试提交更改:
相关问题 更多 >
编程相关推荐