Skip to content

Instantly share code, notes, and snippets.

@luw2007
Created March 20, 2015 15:53
Show Gist options
  • Select an option

  • Save luw2007/270832eed80b82f8e8d7 to your computer and use it in GitHub Desktop.

Select an option

Save luw2007/270832eed80b82f8e8d7 to your computer and use it in GitHub Desktop.
mysqldb 数据库报错

##问: 数据库创建库失败, 报错如下

Traceback (most recent call last):
  File "C:/Users/Administrator/Desktop/phone.py", line 65, in <module>
    xx.execute(edm_info_createtable_sql)
  File "C:\Python27\lib\site-packages\MySQLdb\cursors.py", line 205, in execute
    self.errorhandler(self, exc, value)
  File "C:\Python27\lib\site-packages\MySQLdb\connections.py", line 36, in defaulterrorhandler
    raise errorclass, errorvalue
InterfaceError: (0, '')

##答: 找不到问题所在, 于是远程查看, 久久没有解决, 于是加入断点后调试。 发现数据库连接状态竟然closed, 看之前的代码, 果然封装的方法在调用后主动关闭了连接。

坑。 下次请打印出出错的db连接,及状态

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment