python中的sql语句无法执行的原因 50

从mysql数据库中读取数据,出现sql语句查询错误,sql语句在终端下运行可以正确得出查询结果源码cur.execute("selecthostidfromhostsw... 从mysql数据库中读取数据,出现sql语句查询错误,sql语句在终端下运行可以正确得出查询结果
源码
cur.execute("select hostid from hosts where host = %s",(remotehost)) #取出主机名
rows = cur.fetchone()
try :
hostid = rows[0]
except :
pass

cur.execute("select itemid from items where hostid = %s and key_='system.cpu.util[,idle]'",(hostid))
rows = cur.fetchone()
try:
itemid = int(rows[0])
except:
pass

cur.execute("select value from history where itemid = %s and clock>%s and clock <=%s",(itemid,t2,t1))
rows = cur.fetchone()
try :
cpu = str(rows[0])
except:
pass

cur.execute("select itemid from items where hostid = %s and key_='system.cpu.util[,softirq]'",(hostid))
rows = cur.fetchone()
try:
itemid = int(rows[0])
except:
pass

cur.execute("select value from history where itemid = %s and clock>%s and clock<=%s",(itemid,t2,t1))
rows = cur.fetchone()
try:
softirq = str(rows[0])
except:
pass

cur.execute("select itemid from items where hostid = %s and key_= %s",(hostid,item))
rows = cur.fetchone()
try:
itemid = int(rows[0])
except:
pass

cur.execute("select value from history where itemid = %s and clock>%s and clock<=%s",(itemid,t3,t1))
rows = cur.fetchone()
try:
outgoing =float(rows[0])
outgoing = outgoing/1000
outgoing = str("%.2f"%outgoing)
except :
print "select value from history where itemid =",itemid," and clock>",t3," and clock<=",t1 #把错误的sql语句打印出来
pass
展开
 我来答
WM_THU
2015-05-14 · TA获得超过7163个赞
知道大有可为答主
回答量:4285
采纳率:80%
帮助的人:3854万
展开全部
  1. 请给出具体的报错信息

  2. 根据报错行号,给出其附近的代码

追问

报错就是rows为空,我把异常输出的结果  在mysql终端下运行,可以得出结果

追答
请给出具体的报错信息,包括在except中print的语句。
鬼谷子教主
2015-05-13 · TA获得超过2496个赞
知道大有可为答主
回答量:1996
采纳率:88%
帮助的人:549万
展开全部
具体报啥错?
追问
麻烦您看看楼上的图片
追答
你的正常代码(try部分),并没有print代码,当然不会显示出来。
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 1条折叠回答
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式