因此,我在Heroku上托管的bot出现了问题。确实,我的机器人管理着我用MySQL制作的关卡系统。我的系统似乎运行良好,但是仅在启动bot后的几分钟内。在此期间,所有命令均有效。至少在5分钟后,我的机器人已启动,不再有与数据库相关的命令起作用。编写命令时,日志中将记录以下内容:
2020-10-08T21:51:00.344273+00:00 app[worker.1]: Ignoring exception in on_message
2020-10-08T21:51:00.346163+00:00 app[worker.1]: Traceback (most recent call last):
2020-10-08T21:51:00.346212+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.6/site-packages/discord/client.py", line 333, in _run_event
2020-10-08T21:51:00.346213+00:00 app[worker.1]: await coro(*args, **kwargs)
2020-10-08T21:51:00.346215+00:00 app[worker.1]: File "pabBot.py", line 96, in on_message
2020-10-08T21:51:00.346217+00:00 app[worker.1]: await upgrade_level(message.author, message)
2020-10-08T21:51:00.346236+00:00 app[worker.1]: File "pabBot.py", line 19, in upgrade_level
2020-10-08T21:51:00.346238+00:00 app[worker.1]: cursor.execute("SELECT exp, lvl, exp_time FROM level_users WHERE id=%s;", (user.id, ))
2020-10-08T21:51:00.346241+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.6/site-packages/mysql/connector/cursor.py", line 551, in execute
2020-10-08T21:51:00.346241+00:00 app[worker.1]: self._handle_result(self._connection.cmd_query(stmt))
2020-10-08T21:51:00.346262+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.6/site-packages/mysql/connector/connection.py", line 490, in cmd_query
2020-10-08T21:51:00.346263+00:00 app[worker.1]: result = self._handle_result(self._send_cmd(ServerCmd.QUERY, query))
2020-10-08T21:51:00.346281+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.6/site-packages/mysql/connector/connection.py", line 267, in _send_cmd
2020-10-08T21:51:00.346281+00:00 app[worker.1]: return self._socket.recv()
2020-10-08T21:51:00.346300+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.6/site-packages/mysql/connector/network.py", line 243, in recv_plain
2020-10-08T21:51:00.346300+00:00 app[worker.1]: raise errors.InterfaceError(errno=2013)
2020-10-08T21:51:00.346325+00:00 app[worker.1]: mysql.connector.errors.InterfaceError: 2013: Lost connection to MySQL server during query
2020-10-08T21:51:00.346399+00:00 app[worker.1]: Ignoring exception in command level:
2020-10-08T21:51:00.347478+00:00 app[worker.1]: Traceback (most recent call last):
2020-10-08T21:51:00.347541+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.6/site-packages/discord/ext/commands/core.py", line 85, in wrapped
2020-10-08T21:51:00.347541+00:00 app[worker.1]: ret = await coro(*args, **kwargs)
2020-10-08T21:51:00.347557+00:00 app[worker.1]: File "pabBot.py", line 168, in level
2020-10-08T21:51:00.347557+00:00 app[worker.1]: cursor.execute("SELECT exp, lvl FROM level_users WHERE id=%s", (user.id, ))
2020-10-08T21:51:00.347572+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.6/site-packages/mysql/connector/cursor.py", line 551, in execute
2020-10-08T21:51:00.347572+00:00 app[worker.1]: self._handle_result(self._connection.cmd_query(stmt))
2020-10-08T21:51:00.347574+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.6/site-packages/mysql/connector/connection.py", line 490, in cmd_query
2020-10-08T21:51:00.347574+00:00 app[worker.1]: result = self._handle_result(self._send_cmd(ServerCmd.QUERY, query))
2020-10-08T21:51:00.347591+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.6/site-packages/mysql/connector/connection.py", line 267, in _send_cmd
2020-10-08T21:51:00.347591+00:00 app[worker.1]: return self._socket.recv()
2020-10-08T21:51:00.347594+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.6/site-packages/mysql/connector/network.py", line 243, in recv_plain
2020-10-08T21:51:00.347595+00:00 app[worker.1]: raise errors.InterfaceError(errno=2013)
2020-10-08T21:51:00.347622+00:00 app[worker.1]: mysql.connector.errors.InterfaceError: 2013: Lost connection to MySQL server during query
2020-10-08T21:51:00.347625+00:00 app[worker.1]:
2020-10-08T21:51:00.347625+00:00 app[worker.1]: The above exception was the direct cause of the following exception:
2020-10-08T21:51:00.347625+00:00 app[worker.1]:
2020-10-08T21:51:00.347641+00:00 app[worker.1]: Traceback (most recent call last):
2020-10-08T21:51:00.347669+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.6/site-packages/discord/ext/commands/bot.py", line 903, in invoke
2020-10-08T21:51:00.347669+00:00 app[worker.1]: await ctx.command.invoke(ctx)
2020-10-08T21:51:00.347688+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.6/site-packages/discord/ext/commands/core.py", line 859, in invoke
2020-10-08T21:51:00.347688+00:00 app[worker.1]: await injected(*ctx.args, **ctx.kwargs)
2020-10-08T21:51:00.347709+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.6/site-packages/discord/ext/commands/core.py", line 94, in wrapped
2020-10-08T21:51:00.347709+00:00 app[worker.1]: raise CommandInvokeError(exc) from exc
2020-10-08T21:51:00.347734+00:00 app[worker.1]: discord.ext.commands.errors.CommandInvokeError: Command raised an exception: InterfaceError: 2013: Lost connection to MySQL server during query
这是我的 requirements.txt :
discord.py
dnspython==1.16.0
mysql-connector
当然,我注意到该错误是:
mysql.connector.errors.InterfaceError: 2013: Lost connection to MySQL server during query
我一直在寻找有关此错误的信息,但实际上并没有得到它。 我仍然不知道该错误是服务器端错误还是客户端错误,还是由于我的代码。有关信息,我的数据库托管在 remotemysql.com 上。 另外,我尝试在本地重现该错误,并且它也可以工作。因此,我认为错误并非来自Heroku。
我的代码很大,所以我认为完整发送它不是一个好主意,但是我有一些功能可以让我检查自己的水平,别人的水平并排行榜。
如果你们知道我的机器人为什么不起作用以及错误的根源,我将很乐意为您提供信息!另外,如果您需要更多详细信息,我会发送给他们。
(对不起,我的英语不好,我是法国人^^')
答案 0 :(得分:0)
又是我..原来我弄清楚错误的出处,做了很多测试,结果才意识到我愚蠢地忘记了在命令末尾关闭连接,并在出现错误时重新连接写了一个新的...
因此,我想为这个完全不必要的问题表示歉意,并感谢那些已经看过并且可能寻求帮助我的人。
(如果您还有其他建议,我会很乐意接受!)
再见!