The below script connects to discord, and then disconnects again. that works perfectly and prints out these two items:
**** Logged in!
**** End
But when the script ends, I get this additional warning:
Unclosed connector
connections: ['[(<aiohttp.client_proto.ResponseHandler object at 0x7f18f84e6080>, 3702249.404694462)]']
connector: <aiohttp.connector.TCPConnector object at 0x7f18f70af4c0>
I tried many ways but have not figured out how to et around this; any pointers are welcome. Of course I could simply ignore it, but I'd prefer to handle this "graciously".
Update: Sharing how I have approached it so far. The code I pasted is a minimum working example out of a larger code that allows reproducing the problem easily.
I did try:
Thus any pointers that guide me on the right path are highly appreciated. If people still feel my question is "unprepared", appreciate a comment as to how I could make it better...
import discord
import asyncio
# Suppress login messages from discord
import logging
logging.getLogger("discord.client").setLevel(logging.WARNING)
logging.getLogger("discord.gateway").setLevel(logging.WARNING)
intents = discord.Intents.default()
client = discord.Client(intents=intents)
@client.event
async def on_ready():
print('**** Logged in!')
await client.close()
# Starts the script:
DISCORD_BOT_TOKEN = 'xxx'
if __name__ == '__main__':
client.run(DISCORD_BOT_TOKEN)
print('**** End')
This no longer seems to be an issue.
Re-tested with the following and worked perfectly well:
OS: Ubuntu 24.04.2 LTS
Python Version: Python 3.12.3
Pip Packages:
discord 2.3.2
discord.py 2.5.2
aiohttp 3.11.18
asyncio 3.4.3
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With