我正在尝试执行这段代码:
def getServerSetting(self, setting):
self.dbcur.execute('select value from settings where setting = ?', [str(setting)])
rrf = self.dbr.fetchone()
if rrf is None:
return False
else:
return rrf[0]
但是,当我运行python脚本时,我收到此错误:
dbcur.execute('select value from settings where setting = ?', [str(setting)])
AttributeError: 'NoneType' object has no attribute 'execute'
答案 0 :(得分:1)
尝试编写这样的函数。如果仍有错误,请告诉我。
def getServerSetting(self, setting):
if not self.dbcon:
self.dbcon = MySQLdb.connect(host='localhost', user='removed', passwd='removed', db='removed', port=21)
self.dbcur = self.dbcon.cursor()
self.dbcur.execute('select value from settings where setting = ?', [str(setting)])
rrf = self.dbr.fetchone()
if rrf is None:
return False
else:
return rrf[0]