【发布时间】:2011-09-01 03:02:14
【问题描述】:
我有 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 行,在
枚举文件路径
事件 = Incident() 文件“/usr/share/mwanalysis/core/mysql.py”,
第 23 行,在 init
self.unix_socket) 文件“/usr/lib/pymodules/python2.6/MySQLdb/init.py”,
第 81 行,在 Connect
返回连接(*args,**kwargs)文件
"/usr/lib/pymodules/python2.6/MySQLdb/connections.py",
第 170 行,在 init
super(Connection, self).init(*args, **kwargs2)
类型错误:需要一个整数
异常 AttributeError:“'事件'
对象在
中没有属性“光标” 0xa03d46c>> 忽略
如果有人可以帮助检测和纠正错误,将不胜感激。 提前致谢。
【问题讨论】:
-
那么...您想通过 TCP/IP 还是通过 Unix 域套接字连接?
-
很好,两者都不需要。但是如果连接失败,__init__() 不会引发异常吗?
标签: python mysql database-connection mysql-python