我在关闭连接时遇到了问题,具体如下:
database = 'sed_database'
conn = MySQLdb.Connect(host='remote_host', user='default',
passwd='pass', db=database)
try:
try:
cursor = conn.cursor()
cursor.execute(sql_str)
results = cursor.fetchall()
except MySQLdb.Error, e:
print "MySQL/Server Error using query: %s" % sql_str
print "Using database: %s" % database
raise e
finally:
if cursor:
cursor.close()
if conn:
conn.close()
这将会得到:
Traceback (most recent call last):
File "trass.py", line 579, in ?
main(sys.argv)
File "trass.py", line 555, in main
old_rows, changes_list = auto_analyse_test(f, args.build, args.quiet, args.debug)
File "trass.py", line 352, in auto_analyse_test
last_analysed_build = get_sed_baseline_ref(test_file_name, old_delivery_stream)
File "trass.py", line 151, in get_sed_baseline_ref
results = execute_sql_query(sql, delivery_stream)
File "trass.py", line 197, in execute_sql_query
passwd='pass', db=database)
File "C:\Python24\Lib\site-packages\MySQLdb\__init__.py", line 75, in Connect
return Connection(*args, **kwargs)
File "C:\Python24\Lib\site-packages\MySQLdb\connections.py", line 164, in __init__
super(Connection, self).__init__(*args, **kwargs2)
_mysql_exceptions.InternalError: (3, "Error writing file 'D:\\MySQL_Datafiles\\Logfiles\\query.
log' (Errcode: 9)")
Python的MySQLDB库信息如下:
>>> print MySQLdb.get_client_info()
4.1.18
>>> print MySQLdb.__version__
1.2.1_p2
>>> print MySQLdb.__revision__
410
奇怪的是:
- 我已经在服务器上检查了 query.log 并且它已存在,并由其他进程写入。
- 这段代码可以运行多次,但在某个特定项目上会失败。
- 通过 SQLyog 运行相同的查询正常并返回四条结果。
服务器 error.log 显示 "Aborted connection... (Got an error reading comminication packets)"。
虽然 Traceback 看起来显示错误与连接创建相关联,但直到关闭连接(或函数结束,默认关闭)才会出现此错误。我尝试在打开和关闭之间添加额外的输出或暂停。每次异常都会发生在关闭时。所以什么原因会导致关闭连接时出现此错误?
query.log
的写入权限? - gitaarik