Exception in thread Thread-7261:
Traceback (most recent call last):
File "C:\Users\UCS-TREMBLE\AppData\Local\Programs\Python\Python36-32\lib\threading.py", line 916, in _bootstrap_inner
self.run()
File "C:\Users\UCS-TREMBLE\AppData\Local\Programs\Python\Python36-32\lib\threading.py", line 864, in run
self._target(*self._args, **self._kwargs)
File "D:/python/github/SpiderInfo/Maoyan/getPage.py", line 579, in execSQL
res = cur.fetchall()
File "C:\Users\UCS-TREMBLE\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pymysql\cursors.py", line 295, in fetchall
self._check_executed()
File "C:\Users\UCS-TREMBLE\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pymysql\cursors.py", line 75, in _check_executed
raise err.ProgrammingError("execute() first")
pymysql.err.ProgrammingError: execute() first
以上内容为报错内容:缘由是这样的………………
心血来潮写了个异步执行SQL语句的方法,使用pymysql。担心SQL执行失败,加了个try,代码如下:
@Tools.async
def execSQL(self, sql):
conn = DataSave.connectionDB(DataSave)
cur = conn.cursor()
try:
cur.execute(sql)
except:
logging.error('SQL执行失败,执行语句为:%s'%str(sql))
res = cur.fetchall()
cur.close()
conn.commit()
conn.close()
return res
然后就执行报错了
一看这个错误,也没见过啊,说什么非要先执行,才能match我执行了啊。
仔细一看,大兄弟啊,你一旦sql执行失败的话,直接日志抛出了
然后按照程序再走,好嘛,肯定没有执行sql,然后就去找结果了,肯定找不到啊。
简单修改一下,程序正常跑了。
@Tools.async
def execSQL(self, sql):
conn = DataSave.connectionDB(DataSave)
cur = conn.cursor()
try:
cur.execute(sql)
res = cur.fetchall()
return res
except:
logging.error('SQL执行失败,执行语句为:%s'%str(sql))
cur.close()
conn.commit()
conn.close()
但是发现,就算这种低级错误,在百度上搜索竟然没有一个人说到正点上,最后在国外网站上才找到一模一样的报错内容。
好吧,我承认还是谷歌大法好啊。
广志大兄弟不才,略有收货,即刻分享。