When running a python based discord bot on a droplet, I encounter a "Connection reset by peer" error not present when running locally.

Posted April 24, 2019 1.1k views
DigitalOceanPythonUbuntu 18.04Automated Setups

I am just getting started learning about bots, droplets and everything else, but I have spent several hours bug testing my code on a local system and it runs without issue within its design scope. That said, please bear with any novice questions. I have tried to look for information, and while I understand that the error means Discord is closing the connection on their end, I can’t understand why it would only happen when running the program on the droplet.

The primary function of the bot is to translate English words into a glyph based conlang.

——————————–Explanation of bot function, may not be important——————————-
To do so, when a user sends a message starting with the proper command, the contents of the message are split by space into individual strings for each word, those strings are checked for matches in the keys of a dict variable, that is an actual dictionary in this case. The equivalent word is pulled, then all the translated strings are merged, and saved as a png file (required to preserve the visual due to font limitations), which is sent as a message attachment by the bot.
—————————————————–End of Explanation——————————————————

When running on my local system this process executes correctly, but when running from the droplet, the bot frequently fails to respond to translation commands, and eventually this error log appears in the console:

Ignoring exception in on_message
Traceback (most recent call last):
  File "/home/synake/pybot/six/lib/python3.6/site-packages/discord/", line 255, in _run_event
    await coro(*args, **kwargs)
  File "", line 61, in on_message
    await"ancient.png"), content = rep.str1)
  File "/home/synake/pybot/six/lib/python3.6/site-packages/discord/", line 759, in send
    content=content, tts=tts, embed=embed, nonce=nonce)
  File "/home/synake/pybot/six/lib/python3.6/site-packages/discord/", line 158, in request
    async with self.__session.request(method, url, **kwargs) as r:
  File "/home/synake/pybot/six/lib/python3.6/site-packages/aiohttp/", line 1005, in __aenter__
    self._resp = await self._coro
  File "/home/synake/pybot/six/lib/python3.6/site-packages/aiohttp/", line 497, in _request
    await resp.start(conn)
  File "/home/synake/pybot/six/lib/python3.6/site-packages/aiohttp/", line 844, in start
    message, payload = await  # type: ignore  # noqa
  File "/home/synake/pybot/six/lib/python3.6/site-packages/aiohttp/", line 588, in read
    await self._waiter
aiohttp.client_exceptions.ClientOSError: [Errno 104] Connection reset by peer

Other info: The bot was written on a local system that is running windows 8.1 while the droplet is using Ubuntu 18.04

Submit an answer

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!