【发布时间】:2019-10-12 15:49:02
【问题描述】:
我是 Discord 机器人开发人员,最近完成了一个订单。客户端在他们的服务器上设置应用程序最初没有问题,但据他们说,在运行“大约三个小时”后,程序开始吐出特定的堆栈跟踪错误并且不再接受命令。
机器人是使用 Discord.py 构建的,并使用 Peewee 作为 ORM,使用 PyMySQL 作为数据库驱动程序。客户端运行它的服务器由 DigitalOcean 托管,如果需要有关硬件等的任何信息,客户端可以根据请求向我提供该信息。我们已经尝试卸载并重新安装所有依赖项,并尝试了它们的不同发行版,但错误仍然存在。
这是客户端正在接收的确切跟踪:
File "/usr/local/lib/python3.6/dist-packages/peewee.py", line 2666, in __exit__
reraise(new_type, new_type(*exc_args), traceback)
File "/usr/local/lib/python3.6/dist-packages/peewee.py", line 179, in reraise
raise value.with_traceback(tb)
File "/usr/local/lib/python3.6/dist-packages/peewee.py", line 2875, in execute_sql
cursor.execute(sql, params or ())
File "/usr/local/lib/python3.6/dist-packages/pymysql/cursors.py", line 170, in execute
result = self._query(query)
File "/usr/local/lib/python3.6/dist-packages/pymysql/cursors.py", line 328, in _query
conn.query(q)
File "/usr/local/lib/python3.6/dist-packages/pymysql/connections.py", line 516, in query
self._execute_command(COMMAND.COM_QUERY, sql)
File "/usr/local/lib/python3.6/dist-packages/pymysql/connections.py", line 750, in _execute_command
raise err.InterfaceError("(0, '')")
peewee.InterfaceError: (0, '')
我的 database.py 文件中的相关部分,其中打开了数据库连接:
import discord
from peewee import *
from config import db_host, db_port, mysql_db_name, \
mysql_db_username, mysql_db_password
db_connection = MySQLDatabase(
mysql_db_name,
user = mysql_db_username,
password = mysql_db_password,
host = db_host,
port = db_port
)
def create_db_tables():
# create_tables() does safe creation by default, and will simply not create
# table if it already exists
db_connection.create_tables([User])
我的 bot.py 文件中的相关部分,特别是第一次打开 bot 时运行的 bot 启动函数,以及创建和启动 bot 客户端的行:
client = discord.Client()
async def bot_startup():
# Check for config changes
if client.user.name != config.bot_username:
print("Username Updated To: {}".format(config.bot_username))
await client.edit_profile(username=config.bot_username)
# Start 'playing' message
await client.change_presence(
game=discord.Game( name=config.playing_message )
)
# Prepare database
database.create_db_tables()
print("Database Connected")
print("Connected Successfully")
# ...
@client.event
async def on_ready():
await bot_startup()
# ...
client.run(config.token)
根据客户的说法,重新启动机器人可以暂时解决问题,并且在错误再次启动之前可以正常运行几个小时。一旦错误开始,机器人将不再响应任何传入的命令,如果抛出足够多的错误,则会完全崩溃。
此错误的典型原因是什么,应采取哪些步骤来解决导致该错误的原因?
【问题讨论】:
-
这能回答你的问题吗? InterfaceError (0, '')
标签: python-3.x digital-ocean discord.py pymysql peewee