我有 config.ini:
[mysql]
host=localhost
port=3306
user=root
passwd=abcdefgh
db=testdb
unix_socket=/opt/lampp/var/mysql/mysql.sock
我有这堂课:
#!/usr/bin/python
import MySQLdb,ConfigParser
config = ConfigParser.ConfigParser()
config.read("config.ini")
class MySQL( object ):
def __init__( self ):
self.host = config.get("mysql","host")
self.port = config.get("mysql","port")
self.user = config.get("mysql","user")
self.passwd = config.get("mysql","passwd")
self.db = config.get("mysql","db")
self.unix_socket = config.get("mysql","unix_socket")
self.conn = MySQLdb.Connect(self.host,
self.port,
self.user,
self.passwd,
self.db,
self.unix_socket)
self.cursor = self.conn.cursor ( MySQLdb.cursors.DictCursor )
def __del__( self ):
self.cursor.close()
self.conn.close()
还有这个:
#!/usr/bin/env python
from mysql import MySQL
class Incident( MySQL ):
def getIncidents( self ):
self.cursor.execute("""*VALID QUERY*""")
return self.cursor.fetchall()
最后是这个:
import subprocess, os, alarm
from Queue import Queue
from incident_model import Incident
fileQueue = Queue()
def enumerateFilesPath():
global fileQueue
incident = Incident()
incidents = incident.getIncidents()
for i in incidents:
fileQueue.put("MD5")
def main():
global fileQueue
enumerateFilesPath()
输出:
回溯(最后一次调用):
文件“./mwmonitor.py”,第 202 行,在
main() 文件“./mwmonitor.py”,第 184 行,在 main
enumerateFilesPath() 文件“./mwmonitor.py”中,第 86 行,在
enumerateFilesPath
事件 = Incident() 文件“/usr/share/mwanalysis/core/mysql.py”,
第 23 行,在init
self.unix_socket) 文件“/usr/lib/pymodules/python2.6/MySQLdb/ init .py”,
第 81 行,在 Connect
返回 Connection(*args, **kwargs) 文件
“/usr/lib/pymodules/python2.6/MySQLdb/connections.py”,
第 170 行,在init
super(Connection, self )。初始化(*args, **kwargs2)
TypeError:需要一个整数
异常 AttributeError:“'事件'对象在 0xa03d46c>>
中没有属性'光标'”
如果有人可以帮助检测和纠正错误,将不胜感激。提前致谢。