Причина и решение ошибки Python Bot - PullRequest
0 голосов
/ 30 мая 2018

Я использую питон-бота на виртуальном хостинге, он работает нормально, но через несколько часов ежедневно 1 или 2 раза происходит сбой.Итак, что является причиной этой ошибки и как ее решить.

RuntimeError: can't start new thread
Unclosed client session
client_session: <aiohttp.client.ClientSession object at 0x7f80a690b6d8>
Task exception was never retrieved
future: <Task finished coro=<WebSocketCommonProtocol.run() done, defined at /home/demotry/.local/lib/python3.6/site-packages/websockets/protocol.py:428> exception=ConnectionResetError(104, 'Connection reset by peer')>
Traceback (most recent call last):
  File "/home/demotry/.local/lib/python3.6/site-packages/websockets/protocol.py", line 434, in run
    msg = yield from self.read_message()
  File "/home/demotry/.local/lib/python3.6/site-packages/websockets/protocol.py", line 456, in read_message
    frame = yield from self.read_data_frame(max_size=self.max_size)
  File "/home/demotry/.local/lib/python3.6/site-packages/websockets/protocol.py", line 511, in read_data_frame
    frame = yield from self.read_frame(max_size)
  File "/home/demotry/.local/lib/python3.6/site-packages/websockets/protocol.py", line 546, in read_frame
    self.reader.readexactly, is_masked, max_size=max_size)
  File "/home/demotry/.local/lib/python3.6/site-packages/websockets/framing.py", line 86, in read_frame
    data = yield from reader(2)
  File "/home/demotry/.local/lib/python3.6/asyncio/streams.py", line 674, in readexactly
    yield from self._wait_for_data('readexactly')
  File "/home/demotry/.local/lib/python3.6/asyncio/streams.py", line 464, in _wait_for_data
    yield from self._waiter
  File "/home/demotry/.local/lib/python3.6/asyncio/selector_events.py", line 723, in _read_ready
    data = self._sock.recv(self.max_size)
ConnectionResetError: [Errno 104] Connection reset by peer
Task was destroyed but it is pending!
task: <Task pending coro=<WebSocketCommonProtocol.run() running at /home/demotry/.local/lib/python3.6/site-packages/websockets/protocol.py:434> wait_for=<Future pending cb=[<TaskWakeupMethWrapper object at 0x7f80a6970f48>()]>>

Я добавил свой код скрипта bot.py, как показано ниже, с некоторыми командами, только один bot.py без других файлов.все работает нормально, но вылетает 2 или 3 раза в день.

token = "This is my Token" # This is what the bot uses to log into Discord.
prefix = "?" # This will be used at the start of commands.

import discord
from discord.ext import commands
from discord.ext.commands import Bot

bot = commands.Bot(command_prefix=prefix)
bot.remove_command("help")

@bot.event
async def on_ready():
    print('Logged in as')
    print(bot.user.name)
    print(bot.user.id)
    print(discord.__version__)
    print('------')

@bot.command(pass_context=True)
async def ping(ctx):
    msg = 'Pong {0.author.mention}'.format(ctx.message)
    await bot.say(msg)

@bot.command(pass_context=True)
async def hello(ctx):
    msg = 'hello... {0.author.mention}'.format(ctx.message)
    await bot.say(msg)

bot.run(token)
...