peewee raise err.InterfaceError("(0, '')") 错误

yufei       6 年, 6 月 前       3263

前几天发了一篇文章说大家真厉害,把网站访问挂了,那个时候我以为是代码的问题,所以重启了以下,就好了

但没有去深究为啥挂了

今天早上起来一看,又挂了,好吧,深入了解了下问题,发现下面这个错误

Traceback (most recent call last):
  File "../lib/python3.6/site-packages/peewee.py", line 2625, in execute_sql
    cursor.execute(sql, params or ())
  File "../lib/python3.6/site-packages/pymysql/cursors.py", line 170, in execute
    result = self._query(query)
  File "../lib/python3.6/site-packages/pymysql/cursors.py", line 328, in _query
    conn.query(q)
  File "../lib/python3.6/sitkages/pymysql/connections.py", line 515, in query
    self._execute_command(COMMAND.COM_QUERY, sql)
  File "../lib/python3.6/site-packages/pymysql/connections.py", line 745, in _execute_command
    raise err.InterfaceError("(0, '')")
pymysql.err.InterfaceError: (0, '')

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "../lib/python3.6/site-packages/tornado/web.py", line 1541, in _execute
    result = method(*self.path_args, **self.path_kwargs)
  File "../app/main.py", line 948, in get
    minisite = GetKindByName('Minisite', minisite_name)
  File "../app/v2ex/babel/da/__init__.py", line 47, in GetKindByName
    one = model.get_or_none ( model.name == name )
  File "../lib/python3.6/site-packages/peewee.py", line 5412, in get_or_none
    return cls.get(*query, **filters)
  File "../lib/python3.6/site-packages/peewee.py", line 5407, in get
    return sq.get()
  File "../lib/python3.6/site-packages/peewee.py", line 5805, in get
    return clone.execute(database)[0]
  File "../lib/python3.6/site-packages/peewee.py", line 1560, in inner
    return method(self, database, *args, **kwargs)
  File "../lib/python3.6/site-packages/peewee.py", line 1631, in execute
    return self._execute(database)
  File "../lib/python3.6/site-packages/peewee.py", line 1782, in _execute
    cursor = database.execute(self)
  File "../lib/python3.6/site-packages/peewee.py", line 2638, in execute
    return self.execute_sql(sql, params, commit=commit)
  File "../lib/python3.6/site-packages/peewee.py", line 2632, in execute_sql
    self.commit()
  File "../lib/python3.6/site-packages/peewee.py", line 2424, in __exit__
    reraise(new_type, new_type(*exc_args), traceback)
  File "../lib/python3.6/site-packages/peewee.py", line 177, in reraise
    raise value.with_traceback(tb)
  File "../lib/python3.6/site-packages/peewee.py", line 2625, in execute_sql
    cursor.execute(sql, params or ())
  File "../lib/python3.6/site-packages/pymysql/cursors.py", line 170, in execute
    result = self._query(query)
  File "../lib/python3.6/site-packages/pymysql/cursors.py", line 328, in _query
    conn.query(q)
  File "../lib/python3.6/site-packages/pymysql/connections.py", line 515, in query
    self._execute_command(COMMAND.COM_QUERY, sql)
  File "../lib/python3.6/site-packages/pymysql/connections.py", line 745, in _execute_command
    raise err.InterfaceError("(0, '')")
peewee.InterfaceError: (0, '')

然后就使用 err.InterfaceError("(0, '')") 查了下问题,可能是心情不佳,没找到问题的答案

倒是隐约看到一篇文章说是 MySQL 超时问题,好吧,等等,好像确实是

因为我创建到 MySQL 采用的是全局的方式

暂时就定性为这个问题吧,解决办法也很简单:

  1. 使用连接池
  2. 判断时间,每隔一定时间重连

因为我想放弃 peewee,所以简单粗暴的使用了第二种

lasted_at = 0
now_tm = time.time()

if now_tm - lasted_at > 3600:
    db.close()
    db.connect()
    lasted_at = now_tm
目前尚无回复
简单教程 = 简单教程,简单编程
简单教程 是一个关于技术和学习的地方
现在注册
已注册用户请 登入
关于   |   FAQ   |   我们的愿景   |   广告投放   |  博客

  简单教程,简单编程 - IT 入门首选站

Copyright © 2013-2022 简单教程 twle.cn All Rights Reserved.